Beyond all the confusion and legal issues, one explanation might simply be that there is no border between Hungary and Germany. Whether by train or by road, refugees en route to Germany have to go through Austria and Austria most definitely did not welcome them as of last week.
Austria has been pressing Hungary to accept more asylum seekers through the Dublin system for years (including through a case pending in front of the EUCJ I think) and reports from last week indicate that it effectively reintroduced illegal border controls.
So even if Germany would actually welcome those people (and I am not entirely convinced that that's the case, who knows what communication actually goes on behind the scenes), the Hungarian authorities cannot really do anything with the train without say-so from Austria.
Editing to add: this report suggests the chief of the police in Vienna did indicate they would allow this particular train to continue its journey, which contradicts my initial guess.
New edit: On the evening of Friday September the 4th, after a phone conference with the prime minister of Hungary and apparently with the approval of the German government, the Austrian chancellor indicated that Austria and Germany are ready to let at least some refugees leave Hungary and enter Austria on the way to Germany.
But this report from sueddeutsche.de (a major daily in Germany) presents this as news and suggests that unnamed diplomatic sources previously told the newspaper that this was not on the table and that Germany wanted Hungary to stick to the Dublin system.
Meanwhile, a few thousand people apparently decided to go to the Austrian border by foot and Hungary announced it was ready to provide busses to drive them to the border, so it's not doing anything to stop them in this case.
Bottom line: The situation is still extremely confused but it's by no means clear that Germany was actually ready to welcome these refugees or that Hungary had a choice in the matter until September 4.
Regarding the broader context, EU countries are clearly playing games to position themselves ahead of any negotiation that might come. Germany's well publicised estimate of 800 000 asylum applications “expected” for this year and threat to reintroduce border controls are part of this, as was Hungary earlier stance that it could not take any extra asylum seeker anymore and would just drop out of the Dublin system unilaterally (which is actually already more-or-less the case of all the major countries at the Schengen external border, including Hungary, Greece and Italy, but none of them had proclaimed that openly until now).
So maybe Hungary is trying to treat that one by the book, registering and processing asylum seekers who entered the Schengen area through its territory, as envisioned by the Dublin system, to show its EU partners it's doing everything it can but that it's impossible (the refugees themselves apparently have no intention to comply) and/or confront them with a situation they cannot tolerate because trains going to a “camp” just look very ugly in Europe (but that's a wild guess obviously).
Also, it's an open secret that EU circles and many EU countries do not like the Orbán government very much and do not consider it a reliable partner. It has always been a bit unpredictable.