Is there a minimum amount of time I must spend in a country ?
Is this country dependent? Or I can just enter a country and then exit immediately in 15 minutes or so?
It may lead to additional questioning, but provided you have the appropriate visas / right to access in both countries, there's no theoretical reason you can't.
It's very common at Victoria Falls, where people hop back and forth between Zimbabwe and Zambia on the bridge at the border crossing for photo opportunities, or to get to the bungy jump in the middle of the bridge.
I've spent less than a couple of hours in Paraguay, and less than that in Brazil twice (getting to a border town there from Argentina).
I've walked across to the US from Canada to get dinner, and then walked back a couple of hours later too (that one raised eyebrows but was fine).
I've also bussed into Mexico merely to fly out to Cuba, and I've spent a couple of hours in Lithuania once between flights.
So it's not uncommon, I've never had problems, and legally there's nothing stopping you, unless your reasons for doing so raise concerns with the border guard / officer.
In the Netherlands we have "het Drielandendpunt" (the three-country point). That is where Germany, Belgium and the Netherlands share borders.
You can be in three countries at the same time and nobody cares how many circles you make running around the boundary post.
The green lines are actual country borders.
At several borders there has been a practice called "Visa Run". People would renew their "visa on Arrival" by briefly passing the border to the neighboring country.
Examples are e.g. the Turkish-Greek or Turkish-Bulgarian or the Thailand<-> Cambodia, Malaysia, Laos Borders.
I do this frequently in Canada. Many Canadian airports have no concept of international transit so when flying from the US to Europe or Asia you need to enter and then immediately leave again.
It's quite inconvenient but also sort of funny: the immigration officer often asks "how long do you plan to stay in Canada?" and I'm always tempted to answer: "only 45 minutes but its going to be a lot longer if you don't hurry up"
The common point in the other responses that's not made explicit, is that it is never a problem to stay for an arbitrary small amount of time in one country. What might give you problems is returning to the country you came from.
Obviously, countries with open borders typically won't mind at all. But, if you're hopping borders for a visa run, laws might be in place that will deny you entry, or might see you be hassled by immigration officials of the country you return to.
So, because different visa rules apply to different people in different countries, leaving some country for a very short amount of time and then returning might be problematic. However, staying in some country for a very short time should never be a problem.
I was once in international transit in Germany, and for reasons I do not remember, I needed or wanted to get out to the train station or some other part of the airport. I got lost, so I went through passport control three times instead of once to get out of the international zone. In other words, I entered Germany, exited a couple of minutes later, and then entered again a couple of minutes after that. Then I exited once again a few hours later for my flight. There was no trouble or delay.
There is no minimum time you must spend; I know many people that fly Kuwait - Bahrain - Kuwait (just to reset visa time limits).
They spend less than 15 minutes in Bahrain (that is, time spent from when the visa is stamped entry, till exit stamp). They actually spend more time in the lounge than "officially" in the country.
Similarly, I have done a "day run" to Dubai where I fly out and return the same day.
No issues whatsoever.
I spent 30 minutes in Dubai this year. I went through immigration, out to the mosque in the airport parking lot, found and logged a geocache, and went right back into the airport and through immigration.
I guess it is dependent on the pair of countries. In most of the European Union there is no border control (most of the times) within the Schengen Area. So you may just go across and back.
I would say it is very much dependent on the specific case. Check the border in this question on Stackexchange.
You might get problems if this quick in-and-out looks as if you're trying to exploit a loophole in the law.
A road runs along a good portion of the border between Brazil and Uruguay and crosses the border many times. It goes through the cities of Rivera and Santana do Livramento where for about ten kilometers, the street is the border. You can cross that street as often and as fast as you want (if drivers don't stop you).
Some countries do have different visa requirements for folks who are just passing through (transit visas) versus visas to actually visit the country. Some airports are better than others about handling changing planes without technically leaving the "international" space.
For the minimum duration in country (requiring a visa, rather than the many options that do not require a visa, such as The Hotel Arbez) it may be hard to beat the example at Turkish single-entry visa stamped in transit by mistake. Can I still use it to enter Turkey?. OP does not specify the time interval there but by the sounds of it it was a few seconds rather than a few minutes.
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?