There are four common patterns, and they need different responses.
The door locked behind you while the keys were inside. This is a hardware and habit problem, and it is the easiest to design out.
You had keys but could not use them. The key would not turn, the cylinder was seized, the key broke. That is a maintenance problem, and the lock was almost certainly warning you beforehand; see key will not go into the lock.
You lost the keys. That is a key-control problem, and it may mean more than getting back inside; see lock changes after lost keys.
The lock or door failed outright. A latch that no longer retracts, a multipoint that jammed, a smart lock that stopped responding. That is a repair, and it will repeat until the cause is addressed.
Deciding which one you had takes a minute and determines everything that follows.