Ships keep upgrading to other classes in Stellaris?

Ships will by default upgrade to the latest design you created. This rule is only ignored if there is a new design which has the exact same name as the current one.

So if you have two designs "Torpedo Frigate" and "Laser Frigate", and you research a new type of torpedo, name the new design "Torpedo Frigate" too, not "Torpedo Frigate v2" or something like that. Also save a new version of your "Laser Frigate" design, even when there is no change to it. You can then upgrade all your frigates and they will upgrade to the correct type. Upgrade cost and time depends on the actual differences between the designs, so the upgrade of the laser frigates will be free.

Also be careful when you in some way acquired ships with more advanced parts than you have researched. When you accidently upgrade them, they will actually be downgraded to your inferior design.