I have watched many documentaries and movies about ancient battles, and in almost all of them, the invading army made it their primary objective to capture the enemy's fort. From my little understanding, a fort can only house so many soldiers or combatants, or if the fort is really huge (and housed thousands of combatants), even then, why couldn't the attacking army just go around the fort? What obvious point am I missing here?
So you're a king or general, and you've just embarked on an invasion of a neighbouring polity. Odds are you'll be commanding a considerable number of men and, most probably, a considerable number of horses too. All those men and all those horses are a lot of mouths to feed and water, and you'll probably have a baggage train or an artillery train following your main force. If you're well organised or close to home, you'll probably have a supply network to keep your army fed, or you might have decided to live off the land and forage. But you can't send out all your men and horses to forage in one place or they wouldn't find anything, so you have to spread them out over an area. If you bypassed any fortresses on your way in, well, now your problem comes alive. Unless you want to commit a significant proportion of your forces to guarding your supply column, screening your forage parties or keeping garrisons bottled up, those fortress garrisons are now free to operate in your rear, harass your supply chain, and attack your foragers.
Say you want to lay siege to a city, then you face a similar problem. To effectively enact a siege, you likely need to spread your forces out over a significant area, which means any unmolested garrison forces might be capable of achieving local numerical superiority over you, even if not your whole force. This scenario is illustrated perfectly by the torrid time had by William the Lion of Scotland in his attempt to invade England in 1174. William was forced to leave a significant detachment of his forces to tie up the garrisons of Bamburgh and Alnwick Castle, which then left his forces too under-strength to realistically be able to lay a prolonged siege to the city of Carlisle. This was exacerbated by the Bamburgh garrison's defeat of William's blocking detachment which then allowed them to harrass his supply chains. As William withdrew North to lay siege properly to Alnwick, the garrisons of Newcastle, Prudhoe and other local castles were able to combine and launch a surprise attack on William's siege lines, over-running his forces locally and capturing William himself, plunging the Scottish army into disarray and infighting and leading to their prompt retreat.
Castles, fortresses and whatever else fortifications have been called the last three or four millenia serve several purposes, and I shall list as many as I can.
First they serve as a force multiplier, in that the combat power of one warrior is enhanced by several factors if he is fighting behind cover. Look at the crusader castles that withstood for years despite being massively outnumbered.
Secondly, said warriors would never just sit idle inside the castle. They would patrol, if it was friendly territory. If the enemy was nearby, they would raid. They could either engage pursuing forces, or retreat to a place of safety. Take the knights of St John in Malta in the 15th and 16th century.
Thirdly, once the warriors had been a thorn in the side of their enemies, the enemy would besiege them. Now this is a risky and expensive undertaking and the besieger has suddenly been bound to unfavorable ground - because all the other castles are now gathering around the besieger. Examples of this can be seen in the Flanders Campaign of the war of Spanish Succession - the first Churchill, Duke of Marlborough made his name there.
And as an added bonus - this basic concept still works, just through other means, technology and much longer ranges. Look to the exclave of Kaliningrad and at what is known as (although it's old wine on new bottles) Anti-Acces/Area Denial (A2/AD). Sam J. Tangredi has written a book by that name, that gives a good explaination.
There are many logistical, psychological and political reasons. On a strategic level, however, it comes down to the ability to present or deny battle. Holding a fort gives you the choice to sally forth and fight if the situation is advantageous, or sit tight and wait it out if not. Unless your enemy assaults the fort, in which case at least you get a healthy defensive advantage. Conversely, if you are the invader and you fail to take enemy fortifications you risk losing the strategic initiative, because the enemy can choose when and where battles take place. This can be a real strategic and psychological problem for invading armies.
Some examples you might be interested to look into further:
In On War Clausewitz argues that the inherent tactical advantage of the defensive explains why war doesn't all just happen at once. If your enemy doesn't want to fight due to some disadvantage, surely you should seek battle and push the advantage? In which case fighting would never stop, because one side or the other would always be seeking a resolution. But that's not how wars happen in the real world. There are periods of inactivity. This is because sometimes the defender doesn't want battle, but the attacker doesn't either because they don't have the (approx 3 to 1) numerical superiority an attacker needs to overwhelm the defensive advantage.
During the Second Punic War, when Hannibal was rampaging through Italy and destroying whole armies at Cannae and Trebia, Fabius was appointed Consul. Instead of using forts he used elevation in the hills to withdraw to defensive positions and deny Hannibal battle. Despite being widely decried as a coward by his compatriots for refusing battle (and Hannibal's clever tactic of burning farms and estates of everyone except Fabius, feeding rumours of Fabius being a traitor) Fabius is now credited with finally 'stemming the bleeding' and allowing Rome to recover and ultimately defeat Hannibal. This is known as a 'Fabian strategy', and is considered a precursor to guerrilla warfare.
Border fortifications were often much more than stationary defences. The Great Wall of China was used as a staging post to launch punitive incursions into hostile territory to damage and disrupt nomadic tribes.
The Nazis were famous for using Blitzkrieg tactics to simply go past strategic fortifications as you've suggested. But this was only made possible by motorization: tanks, planes and mechanized infantry. What's less well known is that the Schlieffen Plan in 1914 was based on a similar idea (on a wider geograpic scale) - sweep through Belgium to avoid the heavily fortified Franco-German border. This was more a product of the railways than the motor car, but is also notable for its failure (unlike the fall of France to Nazi Germany).
It really depends on the time-period and purpose of the invasion.
In antiquity and medieval ages, capturing a fort/castle and the local ruler hiding inside was the only way to ensure that you had rightfully claim the land to be yours. While the strongest position in the area is in the hands of your enemy, you can't permanently seize it from them. Over months and years, if the castle/fort is not take, it becomes a strategic threat as ancient/medieval armies were not permanently raised and would eventually disband. This would essentially hand back control of the land to your enemy forces occupying the fort/castle.
Plundering would obviously happen regardless, few armies abstained from doing this especially if it is needed to maintain supplies. In areas that were prone to raiding, cities, towns, castles and forts would be designed to allow valuables and people to hide behind their walls until the raiders departed. This would force armies to lay siege to these fortifications if substantial plundering was their goal.
Therefore, the two primary functions of ancient/medieval warfare (conquering and raiding) require the invader to besiege fortified positions to truly achieve their goal.
As armies became more mobile and professional, forts became more of a threat to armies. A single fort could protect a city without surrounding it. While an army could in theory go around it, artillery (which became more and more of a threat), could shell the army the entire time without taking casualties. Armies trying to "go around" a fort would find that the troops inside were now able to attack them in their flanks and rear, or cut off their supply lines entirely. So by ignoring the fortifications instead of dealing with them, you could end up cutting off your entire force and destroying it.
A good example is the American Civil War. The capital cities of the Union and Confederacy were only about 100 miles apart, a disciplined force from either side could have reached the opposing army's capital within a few days. What stopped them from doing this was lines of fortifications that became stronger and stronger as the war progressed, both sides became experts in "digging-in" as soon as they set up camp. Small forces could get in front of larger ones, placing their defences in the way of the enemy's objective. Tactics of the period involved forcing the enemy to either confront these defences or make flanking manoeuvres that would leave them vulnerable to attack or isolation. An isolated army could be destroyed by attrition, demoralisation or an attack from all sides.
Now that armies can move hundreds of miles in a day, stationary fortifications are far less important. Modern artillery, missiles and bombs can now reduce fortifications without going anywhere near them.