Whatever battery you want to charge, the incoming charge voltage must be higher than that of the battery - often by a significant margin.
Your "12V" panel is probably giving out 14-19V at any point - because that's what it takes to charge a 12V battery.
To charge a 24V battery, that's obviously not sufficient. The voltage from the panels MUST be higher than the battery voltage in order to charge (simple physics).
So you can join two "12V" panels in series and this will give you enough to charge two 12V batteries in series (which is what a 24V battery basically is).
There are, however, limits - the controller charger will tell you what the maximum input it can take will be. It'll also tell you what the maximum battery it can charge will be (and that will often have to be selected by the charger for the right battery, e.g. 12/24/48V).
However, you also need to be careful to ensure that the individual panels are also able to connect in series (they will tell you what the most panels you can have in series will be) and that the current is within limits for the cables you're using.
It's definitely not a "this can't be done". It can, and it's very ordinary. You just have to know that your equipment is all capable of doing so and specified properly and fitted within specification. You can't just keep stringing dozens of random panels together on their original cables and feed it into any controller and expect it to charge a battery it wasn't designed for safely.
Check your equipment - all the panels I've bought tell you exactly what series/parallel configurations they support, all the controllers I've used tell you exactly what they expect for input voltage and output voltage for your battery, and all the batteries I've used will tell you what the minimum charge voltage and the most voltage they will safely accept is (and if they can be strung together in parallel and series configurations, and if so how many).