The past Present and past modal structures To say that something was or wasn't necessary, we use had to/didn't have to:
Ella's car broke down, so she had to take a taxi.
There was nobody at the desk, but luckily I didn't have to wait long.
To express regret or criticism about something that happened or didn't happen, or to give advice, we use ought (not) to/should (not) + have + Past Participle: We should have booked/ought to have booked a different hotel. This one is terrible.
My parents shouldn't have sold/oughtn't to have sold their camper van.
To say that an action was not necessary, we can also use didn't need to + infinitive or needn't have + Past Participle. There is a difference in meaning:
I didn't need to cook dinner for the children yesterday because they were away. (So I didn't cook it.) - I needn't have cooked dinner for the children yesterday because they weren't hungry and didn't touch anything. (I cooked it but didn't have to.) The modal verb must and the structure had better are not used in the past.