When background apps close on its own to save RAM, for example. It depends on how hungry is the next app you open.
iPhones work very differently when compared to Android. By default, there really aren’t backgroud apps, iOS forces their usage to minimum. iOS has own thread for UI rendering and everything on background is not prioritized.
And yet when you leave Safari (or any other browser) and use other apps and come back, and have your tab(s) reload and lose your position in a long webpage or have to re-fill a form... sometimes happens even after 10 seconds... then you wish you had more RAM
To be honest I never ever noticed this. I have a lot of apps at a particular time used and switching between them is instant and gets me to the last position and state every time.
The - seemingly - easiest way to trigger this is to stream audio via the Music.app, have Apollo (Reddit-client, og Reddit app may be even worse) in foreground and switch back and forth between those...
I use official reddit app, spotify, audible, browser, crypto apps, lichess, maps and probably some other apps and frequently switch between them and they always keep their state.
That is app specific behavior and probably working as intended from the OS point of view. OS prioritizes the UI and background apps are even stopped, if they are poorly implemented. This is not the fault of missing RAM, instead app developers should know what OS does in these situations and reload the situation from the cache, not from the RAM, depending on their implementation and needs.