Broadly the rule on "lose on death" / "keep on death" roughly mimics the experience of the original Elite, where you could only save your game while docked at a station.
"Lose on death": things you probably picked up since/at your last docking.
"Keep on death": things you probably had since before your last docking.
So credits, materials, ranks, reputations, etc. you mostly had before you docked last, so you get to keep them.
Cargo, exploration data, bounties, etc. you mostly didn't have when you docked last, especially if you're on a standard "do things, hand in, repeat" game loop, so you lose them.
For simplicity the rule is per-type - you keep the credits and rank since your last docking, and you lose exploration data even if you docked since obtaining it - rather than it actually returning you to your "last docked" state. This also cleans up some duplication exploits which would otherwise exist if it actually tracked when you got everything and reset you to a literal "last save point".
It's a very logical rule from an out-of-game perspective, but don't attempt to make any sense of it in-game because it doesn't. Almost every new thing added after 1.0 - including materials - has been added to the side this rule suggests. The only exception I can think of to it - and, surprise, one which gets a lot of complaints! - is that you lose crew on death even though you probably had them and most of their XP since before your last docking.