I had this issue on my Nintendo Switch for almost all of this month (March 2021). I ended up signing out of my Microsoft account on my Switch, deleting my saved data for Minecraft on the Switch, and then logging back in brand new. It signed me in to my account and I can play on Realms again. It's been good all week so hopefully that helps someone else with a Nintendo Switch.
I had this issue on my Nintendo Switch for almost all of this month (March 2021). I ended up signing out of my Microsoft account on my Switch, deleting my saved data for Minecraft on the Switch, and then logging back in brand new. It signed me in to my account and I can play on Realms again. It's been good all week so hopefully that helps someone else with a Nintendo Switch.