I have used the code from github and in that code i am implementing the raspberry pi and the RFID and relay module with magnetic door unlock. Everything is working Okay , the RFID , the Relay module and the button. When the Card is scanned the relay module light turn on and i can hear the tick sound of the relay as well (with no current being passed in the 12 V Magnetic Door ) and the Button as well , when i click to unlock via button it works perfectly as well without the Magnetic Door. The issue comes when 12 V power is passed to the Magnetic module, in this case the RFID scans the card for the first time and the relay light is on and the module is working correctly but as soon as the relay module goes off the RFID card stops working. But the Button keeps working. I can unlock via button many times but the RFID cards works only for the first time and again to make it work i have to restart the Raspberry. I have checked the whole code and the whole connection and everything is right , everything is working perfectly until 12 V current is passed in the relay. Just for the information , i have ordered different relays and tested with them as well but still same.
I have seen exactly this problem on a very similar application. Instead of a solenoid it was a common magnetic relay that was being activated to control mains power to a piece of equipment.
I finally found that the problem was a subtle incompatibility between the RFID library and the connections of the Pi to the RFID module. It turned out that the code was not actively driving the reset pin to the module. But, you said you've check both of these and you are sure they are correct so that can't be it.
The OP has a Rpi based electric door lock system which can be operated by either manual push button or RRFID card.
In normal operation the relay controls the electric lock power by 12VDC. When testing before 12V power in on, everything goes well: both push button and RFID card can activate and deactivate the 5V relay (hearing relay clicks).
However, when 12V lock power is switched on, only push button can activate and deactivate relay as before, this time also lock is activate and deactivate.
The big problem is this: RFID can perform the activate/deactivate only once. After the only one off operation, Rpi need to reset to do RFID operation again.
The OP wishes to know why the Rpi should be reset after every RFID operation, and of course how to avoid this silly unnecessarily Rpi resetting.
The OP confirms that even the 12V power is switched on before any test, the RFID's only one operation problem does not go away.
There are two types of electric lock: (a) NO (Normal Open), (b) NC (Normal Close). I am assuming the OP's lock is NC (Normal Close).
For NC lock, the +12VDC power wire goes to relay channel's COM terminal, and goes out at the NC terminal.
When 12V power is switched on, COM and NC is shorted. So +12VDC goes to the positive terminal of the lock. The negative terminal of the lock goes back to the Ground (0V) of the 12VDC power supply.
Now when the RFID reader reads a RFID card, Rpi will checks if RFID card read is valid, and if yes, would trigger the Relay channel. Now COM will disconnect from NC. In other words, the 12VDC power to the lock is cut off.
Now the fun starts at this point. The lock is actually a solenoid, which is an inductor. Now when the power to this inductor is cut off, the current flowing through the inductor path is cut off, and a back EMF voltage and resultant current would occur and flies back through a flyback diode, if there is one.
Either with or without a flyback diode, the back EMF will still trigger a spike voltage signal, and returns to the power ground.
If the 12V power supply ground line is physically connected for any length to the +5V logical power ground line of the Rpi, Rpi would experience a voltage spike and resets the RFID program running at Rpi.
So Rpi needs to be reset to restart the RFID program, and this is what annoyingly do after each RFID operation.
There are a couple of workarounds. The main idea is to decouple the 12V relay and lock power from to the 5V Rpi power.
If the OP is using a relay with a JD-Vcc jumper, he can do total optical isolation, as described in Appendix D.
The explanation of the JD-Vcc jumper operation is described in Ref 7.
There are other tricks to prevent relay/lock power from interfering the 5V Rpi logic power from the 12V relay/lock power. These trick include:
(a) Space power lines from logical/control lines
(b) Use two separate power supplies, one 5V (not stepped down from the 12V relay/lock power supply) Rpi, another 12V dedicated for relay/lock.
This is a troubleshooting question. I think we need to first study the Rpi python program to see how it works.
/ to continue, ...
(26) DC6V 1.5A 11.4mm 200g Electromagnetic Solenoid Door Lock - AliExpress US$14 (The OP's solenoid door dock)
Appendix A - LX230 RFID Rpi python program listing
The main test program, without the RFID library, is only 80 something lines long. So it is worth our time studying carefully the complete listing.
LXF230-RFID-Door-Lock/SimpleMFRC522.py - lesp 2021apr25hkt2156 https://github.com/lesp/LXF230-RFID-Door-Lock/blob/master/SimpleMFRC522.py import MFRC522 import RPi.GPIO as GPIO class SimpleMFRC522: READER = None; KEY = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF] BLOCK_ADDRS = [8, 9, 10] def __init__(self): self.READER = MFRC522.MFRC522() def read(self): id, text = self.read_no_block() while not id: id, text = self.read_no_block() return id, text def read_id(self): id, text = self.read_no_block() while not id: id, text = self.read_no_block() return id def read_id_no_block(self): id, text = self.read_no_block() return id def read_no_block(self): (status, TagType) = self.READER.MFRC522_Request(self.READER.PICC_REQIDL) if status != self.READER.MI_OK: return None, None (status, uid) = self.READER.MFRC522_Anticoll() if status != self.READER.MI_OK: return None, None id = self.uid_to_num(uid) self.READER.MFRC522_SelectTag(uid) status = self.READER.MFRC522_Auth(self.READER.PICC_AUTHENT1A, 11, self.KEY, uid) data =  text_read = '' if status == self.READER.MI_OK: for block_num in self.BLOCK_ADDRS: block = self.READER.MFRC522_Read(block_num) if block: data += block if data: text_read = ''.join(chr(i) for i in data) self.READER.MFRC522_StopCrypto1() return id, text_read def write(self, text): id, text_in = self.write_no_block(text) while not id: id, text_in = self.write_no_block(text) return id, text_in def write_no_block(self, text): (status, TagType) = self.READER.MFRC522_Request(self.READER.PICC_REQIDL) if status != self.READER.MI_OK: return None, None (status, uid) = self.READER.MFRC522_Anticoll() if status != self.READER.MI_OK: return None, None id = self.uid_to_num(uid) self.READER.MFRC522_SelectTag(uid) status = self.READER.MFRC522_Auth(self.READER.PICC_AUTHENT1A, 11, self.KEY, uid) self.READER.MFRC522_Read(11) if status == self.READER.MI_OK: data = bytearray() data.extend(bytearray(text.ljust(len(self.BLOCK_ADDRS) * 16).encode('ascii'))) i = 0 for block_num in self.BLOCK_ADDRS: self.READER.MFRC522_Write(block_num, data[(i*16):(i+1)*16]) i += 1 self.READER.MFRC522_StopCrypto1() return id, text[0:(len(self.BLOCK_ADDRS) * 16)] def uid_to_num(self, uid): n = 0 for i in range(0, 5): n = n * 256 + uid[i] return n
Appendix C - Wiring Diagram
Appendix D - JD-Vcc Jumper Relay Wiring Diagram
Appendix E - Total optical isolation wiring diagram for the OP's application
Appendix F - Flyback Schottky Diode to protect PSU powering Magnetic Door
Appendix G - N-channel Power MOSFET Controlled Magnetic Door Lock v0.3
Appendix H - YL-03 Solenoid Door Lock and IRL540N N-channel Power MOSFET V0.4
Appendix I - IRL540N Pinout
Appendix J - Wiring of Using N-channel Power MOSFET to switch on/off a 12V Solenoid/Marnetic Door Lock
/ to continue, ...