Yes it's something that happens and has been questioned on the forum before.
I think if the S Pen is not used for a while. I guess to save a small amount of battery power, must put it in some sleep mode.
Reinserting the S Pen for a few seconds, charges it up and all good.
You can always go into settings and go into Advanced Features.
Go into S Pen and more S Pen settings.
Then select keep S Pen connected