Have you read your owner's manual?
My car does weird things. I cannot lock the doors with the solenoids if a door is open and the key is in the ignition. However, I can lock the doors manually with the key from the outside if the doors are closed....... even with the engine running. If I unlock the door with the key fob, it gives me three seconds to open something before it locks everything back up again.
Read your manual.
If you're still having problems, we'd need to at least know the year, make, and model to even begin to help.
I'd also like to know if you've had the battery changed recently. Often in today's cars Body Control Modules need to be reinitialized after changing the battery. Been there, done that.