It's simple, the two drain pipes are connected, and the floor drain pipe is partially blocked, almost completely blocked. Immediately open the branch drain line serving these two traps. Otherwise, you could damage the bathroom floor, the ceiling below, or both, and insurance companies will not be able to pay due to lack of maintenance (or at least they will use it to reject claims). You may also use too much soap and / or shampoo to cause foam, but this is rare.
The cause of the blockage is usually hair. Removing the screen of the shower drain pipe (usually two screws) may get good results (be careful not to let them fall on the drain pipe). When connected to the bottom of the grate, you may leave a long stream of delicate hair, soap, skin cells and other body and human activity waste, so prepare a bucket and wear protective gloves. Or hire a licensed plumber or drain cleaner. There may also be other dirty things. At this time, just open the screen to clean up the dirty things. Then reinstall the screen, and you can use it normally.