This is true now - it definitely wasn't in the past, especially until the 80s. My mother was still beaten (!) as a child by her teacher in Munich when she spoke too Bavarian. Eradication of dialect was the goal at the time, Hochdeutsch the only thing acceptable.
(But the reason was people thinking it's a "Bildungshindernis", a roadblock in the pursuit of knowledge, like if people speaking dialect were mentally challenged - not national unity)