Hello, there may be several reasons why your phone does not accept the code
One problem can be that the phone is non-updated or after firmware downgrade. Just upgrade the phone to the last firmware and do the master reset, the phone will accept the codes.
Check that your phone doesn`t require Freeze code. If asks for Freeze - enter it first and then Network code.
P.S. NETWORK PUK code = freeze code.
Also, check maybe it is TMB phone with not original firmware.