I learned Bokmål Norwegian through my Norwegian friends, and they spoke and wrote to me in it consistently, while some of their patients would use heavy dialect that I didn’t understand at first and was shocked how different it sounded. Hva for noe - sounded as “Ka fo noka” from her mom, shouting through the house, to inquire on something…
I think you meant "parents" not patients - I was a bit confused at first :-) What happened to you is probably that your friends, for your sake, tried to "speak" Bokmål to you (Bokmål is a written, not normally spoken language), as in practice that's how you have to teach Norwegian to foreigners. You have to come up with something where the writing and the speech actually matches. Where my wife was taught they did it…
Not entirely sure why they switch. Was it to "be cool" with friends? Or to suck it a bit up to authority figures?