There are several factors to consider but first, it's not really true that Hungary “let them in” in the first place. It's difficult to get precise info on this but as far as I know many of the people you hear about in the news actually crossed the border illegally (refugees cannot be punished for this, incidentally). However, others possibly presented themselves to the border to lodge an application then and there (which everybody is entitled to do under EU law).
The first problem for Hungary is that it's extremely difficult to secure a land border, humanely and cost-effectively. The US has poured a lot of money into securing its border with Mexico, which often runs through very hostile terrain and yet hasn't made it completely impassable. Spain has built a huge fence on the tiny border around its exclaves in Morocco and that hasn't actually stopped people from crossing so that it had to resort to aggressive (and illegal) police tactics to push them back (to fix ideas, the Ceuta Border fence is 6-metre high but only 8.4 km long, secured by hundreds of police, with cameras and watch-posts; Hungary has 175 km of border with Serbia and already built a 3.5 m fence behind rows of barbwire).
Hungary did receive money and support from the European Union but the EU is not ready to provide the kind of funding or condone the kind of aggressive tactics that would be necessary to stop people who are desperate enough to take a 1 in 125 chance of drowning to reach Europe. Nobody wants an iron-curtain-like border in the middle of Europe!
And there is also a limit to what the police can reasonably do. If you face small group of people on foot, you can apprehend them and bring them to a processing facility but those are completely overloaded (see below). And it does not work when you have many more refugees than police officers (refugees are not stupid incidentally, they respond to police tactics, that's why you are increasingly seeing massive runs of people all crossing at once instead of small groups trying to sneak in). There were instances in Spain where the police basically tried to “push” people back with truncheons, outside of any established procedure, but that has been heavily criticised and might not be enough on such a long border. And obviously, shooting on sight to deter people from crossing, as some European countries did in the past, is not acceptable in this time and place.
One bit of information on the magnitude of the problem comes from Frontex, the EU agency tasked with coordinating the management of external borders (incidentally, Frontext does not directly man border posts or protect anything, it only employs about 300 people and provides training and information sharing). It counted more than 40000 illegal crossings through what it calls the “West Balkan route” in 2014 and more than 100000 for 2015 so far. So according to these figures, many asylum seekers did enter irregularly.
Anyway, if someone is caught crossing illegally or present themselves to the border without visa, they are allowed to lodge an asylum application. What's supposed to happen then is that the person can be detained (in a specific facility, but not in a prison, even if e.g. Germany repeatedly broke this rule in the past) so that the credibility of their application can be evaluated. If it's not manifestly unfounded, they will be allowed to remain in the country (sometimes in a special facility, sometimes in another set-up) until a final decision is made. This is also how it happens in airports everywhere in Europe.
The second problem for Hungary is that this process takes time and resources. According to Eurostat, after a spike in the late 90s, Hungary usually processed about 2000-4000 applications a year during the 2003-2010 period. This should also approximately be their current capacity (trained personnel, accommodation, guards, etc.) for handling asylum applications. Last year, it was more than 40 000 (ten times as many) and now the press reports numbers on the order of several thousands a day.
And processing an asylum application is not trivial. In theory, you are supposed to have translators available so that the person can communicate effectively and you need people who know the country where they come from to check their story (e.g. if they claim to come from a given city, you ask the name of a mountain next to the city, etc.) and of course the relevant rules and regulations. Even simply guards/police or personnel able to register the details of asylum seekers (without actually examining their application) have to be recruited and trained, which cannot happen overnight.
That means that the whole system is currently completely overloaded, there are no facilities to host these refugees, no places where they can be detained, nobody who could do even a preliminary evaluation of their application. Even basic things like providing shelter and water are difficult (although that's what the HCR is doing along with many NGO and the local government for millions of people in Turkey or Jordan). Because the conditions are so bad, people try to break out of the camps as soon as they can and that's how they end up on the streets.
Incidentally, directive 2001/55 on minimum standards for giving temporary protection in the event of a mass influx of displaced persons and on measures promoting a balance of efforts between Member States in receiving such persons and bearing the consequences thereof provides a procedure to deal with such a crisis.
One interesting aspect is that there is, under international law, no reason for the refugees themselves to accept our notion of where they should go. So what the directive envisions, in theory, is a system of transfers between member states subject the consent of the persons concerned.