Your school lab work is only valuable to yourself and other students who wish to plagiarize, there's not really a compelling reason to share that code.
If you're writing other software beyond classwork that you wish to share, the school has no say over it, no more than they would if you chose to write a book while in school.
I always found I learned a lot more when I expanded upon the coding assignments and added my own features. Not only did I learn more, I found it much more enjoyable. In some cases it took something that would have just been an assignment and turned it into something useful for me. I’m not sure why not being able to share the code with the world would change the value proposition of doing that stuff?
I also have to assume there is some limit on how long you’re expected to hide your work away? After you graduate, if you make the repo public, what are they going to do?