Sure, why not. Constructions like “it had to be done”, “I had to” come up If you are telling a story that happened in the past, or in something like “I know I had to do X, but something else happened”.
Sounds difficult, because there’s nothing to put into past tense. If you really want to, maybe it’s an option to self-quote, e.g. 「『行かないと』と思った」, but at this point is it really the same construction.