The approach varies over time, usually based on what USNA leadership (especially the Dant) wants to do.
Some classes stay with their companies from the minute they enter USNA to the minute they graduate. That was the case in my day.
Our plebes all switched companies after plebe year. Not sure how long that lasted.
There are variations on this theme -- switching after plebe summer, switching after the summer and after plebe year, switching after youngster year, etc. Just b/c it's a certain way at the moment doesn't mean it will continue that way -- especially if leadership changes.
The theory behind switching, BTW, is to give mids a "fresh chance" in their new companies. IOW, people can quickly get tagged as exceptional or exceptionally bad and the thought is that, by moving everyone, an unwarranted halo effect or bad rap can be changed. Not sure whether/how well that works in practice.