Check if the IMEI is blacklisted first. If that's the case, it's usually because the phone bill wasn't paid or the phone was stolen. In this case, it's more or less useless as a phone. Check the status of the IMEI on a site like Swappa. Since we now have global blacklists the phone is useless everywhere; even for international use.
If the IMEI is bad, take the phone to the police and ask what you have to do to claim legal ownership if you want to keep the phone. Some states allow you to turn it into the police and let you claim it legally if the original owner doesn't speak up within a certain amount of time. Even if you get it this way do not expect the carrier to help you or use the phone portion ever again. That part is probably going to remain blacklisted since the carriers require the original owner to call when it comes to unblocking a stolen phone. I'd even advise against a IMEI swap.
If the IMEI comes up clean, do a Recovery Mode restore. If that works, it was something with the baseband that caused the issue that was recoverable. It's usually a carrier software problem when this works. Follow this guide to access Recovery Mode: iDevice Recovery Mode Restore
If the Recovery Mode restore doesn't fix the phone, it's a hardware baseband problem. These require a new motherboard, since the baseband chip is typically paired to the board. Follow this guide to replace the board: replace the logic board. I don't think this is worth it, since whole phones and the boards tend to cost about the same.
If you swap board I'd suggest getting the original IMEI if you can to verify the IMEI on the new board is good, but you won't be able to do this all of the time. Sometimes you can get the correct back if the parts are sold as a pair, but this is not very common since most sellers break these parts up.