If you get locked out of any terminal while hacking, you should only get locked out for 24 hours. After this, it should be unlocked for hacking again. If there is a bed nearby, you can just sleep it off and come back to try again. Hacking terminals is quite easy in Fallout though, once you know how it all works, you should be able to unlock most of them without too much trouble. Here is a guide i wrote for hacking terminals this should give you all the info you need about hacking terminals in Fallout 4.
For the record, the mechanic has been unchanged since fallout 3, so the same rules apply to all 3 of the Fallout games that have been released so far.