It happened a couple of times I had items stolen from my home or car because I simply forgot to lock the doors.
Is there a trick to prevent this absent-mindedness?
Some answers give various solutions for the house lock but not the car lock.
I have spent so may hours looking for my car keys that I now habitually only ever leave them in one place.
An extension of that would be to have two key hooks. You label one hook "locked" and the other "forgot".
Then when you hang the car key on the hook, the reminder is there. Hopefully, the second hook is never used except as the reminder, or maybe you want to leave the car unlocked for now, to load/unload it, and you'll notice later that the key is on the wrong hook.
In general I have found that a simple reminder notice does not do any good, because I get so used to seeing it that I ignore it after a while. So swap the labels around once a week.
It sounds pretty simple, but it works (for me).
Whenever you close the door, immediately lock the door as well.
Try to combine this into one action: with one hand you pull the door closed while the other holds the key and locks the door.
You should aim to never do anything between closing the door and locking it.
The shorter time there is and the fewer things you do between when you close the door and when you lock it (on average), the stronger your brain will associate these two things and the easier it will be to remember to lock the door (you might even start automatically doing it after a while).
Even if the door closes by itself (e.g. with a spring), you can still use this strategy by always making sure to manually close the door instead of letting it close by itself.
Pro tip: if you don't need a key to unlock the door of your house from the inside, don't ever put your keys in your pocket or bag while inside. Instead, put it right next (or on top of) to whatever else you always leave the house with (e.g. your wallet or bag). Then you'd pick up your keys when leaving the house and you should physically keep them in your hands while going out the door, which would make it much easier to remember to lock the door.
If you regularly make multiple trips to your car (or similar) and the car is far enough to close the door (but not lock it) or the door closes by itself, this may not work perfectly. But you may still be able to combine it with any "final check" you may do the last time you go through the door. Or split it into multiple trips where you first put everything by the door on the inside, then on the outside (then lock the door), then carry it to your car.
You can use this in combination with the above.
Put your keys on the table (at home) or in your pocket or bag (when going out) immediately after locking the door.
If you're still holding your keys and you didn't just lock the door, you need to go lock the door (or at least check if it's locked).
I quite frequently use this strategy of combining things I want to remember with things I already do.
This would probably work best if you're already very intentional about and conscious of your actions (instead of doing things absent-mindedly). Although, if you aren't, trying to do what's suggested here might help with that, at least a little (because practice makes perfect).
I have a 'leaving the house mantra' of "Keys, Wallet, Phone, Id".
Part of the mantra is to tap the location each of these items to confirm it is there, then I grab my keys so that I have them in my hand, ready to lock the door after me, and unlock the car door. The physical reinforcement helps to solidify the connection between the thought and the action - You don't just know that you have everything you need, you feel it too.
I don't have a similar ritual for leaving my car, as my car keys are always in hand after turning off the engine, but I do always check mentally that I've locked it before walking away, and check physically if I'm not sure.
As houninym suggests, it doesn't take many repetitions to form a habit. Do it every time, even when you don't need to, and soon it should become a self sustaining habit.
There's a saying about it taking three repetitions (or 21...) for something to become a habit. A 2009 study seem to indicate it takes about 66 days to become habitual - https://metro.co.uk/2016/12/30/how-long-does-it-take-to-change-a-habit-6351291/. So you need to remember to lock your house and car every time for a couple of months for it to become an ingrained habit.
If that's true for you , there's no point in spending a lot of money to change your house locks... just a post-it note highly visible on the exit door for two months may be enough. The same for the car might be enough. After two months being reminded to lock the door it may become habitual!
It's also something that you may get financially reminded of... most household or car policies won't cover you if you leave the house / car unlocked. So if you walk out the door and find your nice car gone because you didn't lock it, or come home to find the place ransacked because you didn't lock up after yourself (and your car stolen because your car keys were on the table in the unlocked house) you won't find the police or the insurance company very helpful.
It is not going to work on a car, but I think it is worth mentioning.
The Berlin key is a key for a type of door lock. It was designed to force people to close and lock their doors, usually a main entrance door or gate leading into a common yard or tenement block.
Source video: https://youtu.be/UW4jZLEgaiU
Another video: https://youtu.be/4wE_6e3GPe4
When you turn off the engine after parking, don’t actually pull the key from the ignition just yet. Instead, gather whatever you want to take from the driver’s seat and take the key last. Put your finger over (but don’t press yet!) the button to lock. Exit the car with your finger still over that button.
Two options here: either you want to get something from the back seats or boot or you don’t. If not, close the door, lock, and put the key away. If yes, get that but keep the finger on the lock button. Close whatever else you opened, lock and put the key away.
What about if you need to get something that you can’t carry right now? I suggest locking the car anyway. With time, you will generate the automatism that you lock the car whenever you go away from it and unlock it once you get back. 200 ms inconvenience for great benefit.
How can I remember?
That's a mind hack, and not on topic for this site. You can however mitigate the effects of forgetting to lock using technology:
For houses: Fit a self-locking door lock that is unlocked by a code or fingerprint, or keep a key well hidden (not under a plant pot next to the door) in case you become locked out. Upgrades from this level of locking would probably be something like a smart home type intelligent door lock that can be secured remotely using a phone etc - and if you have that you might also have movement sensors inside the house that can lock the doors after a period of no activity
For cars: keep nothing of value in a car, and don't bother locking it. If you do lock it, have a spare key attached to the car somewhere (magnetic boxes exist for this purpose). Consider fitting an aftermarket alarm that will lock your doors for you after a time out. If you're then concerned that this device will lock the car keys in the car, defer to the aforementioned magnetic box idea - it doesn't have to be a sophisticated key with a transponder for starting the engine, deactivating the alarm etc - just a mechanical key that will go in the mechanical lock in the door and open the door will be enough to regain you access to the intelligent key that is locked inside the vehicle
The obvious answer is habit. Need to build a routine that involves locking the respective doors. For the car, perhaps using your backseat to place your duffle bag that usually goes with you. Grab the bag then lock the door using the fob. Always anticipate the beeping as the last step before you walk away. The house might need a keypad lock. Similar idea though. Last step before walking away from the door in or out should be wanting to hear the lock engage. Note: if you're married, you probably already have developed the habit of putting the toilet seat down! So there is hope!