This is a known limitation. In certain times it works very well and realistically, there are many instances in the world history of warfare that separate peaces were signed. Actually, technically, it is the only thing you can possibly do unless you explicitly ask for other nations to be involved.
But in the game abstracted it is indeed a problem. Perhaps in a future version of the Athena logic, it could be added that if A is at war with B and C is at at war with A, if C defeats A while A defeats B... A should automatically lose any progress against B as well. In game terms: Prussia should have been forced by the game logic to stop the war with Bavaria, even if it had positive warscore against it. Losing badly (and having own objective cities occupied) should be a huge incentive for the AI to stop any other ongoing wars and dedicate to defend against the major danger.
Another solution could be that in games like PON it could be added as a peace treaty demand option: end ongoing war with... (nation in question, not necessary ally but ally could give more prestige points if successful)
I think it is doable, logic-wise, but it's up to the Philippes to implement.
PS. The solution to your problem, albeit gamey, is rather nice however. After you concluded peace with the Prussians you could park "peacekeepers" in your ally Bavaria. These will make sure that Prussia won't be able to enter Bavarian territory and if they do they won't be able to occupy anything. The AI sometimes ends inconclusive wars that last for a long time, but not always. Actually this is something else that might need further work.