From what I've learned from the internet (sigh) the only way to get through castle walls it's either by climbing them (e.g stairs, siege towers) or a ram. So, why didn't they fully block the entrances to stop any threat from the latter?
They didn't for several reasons.
Probably the most important factor is that while a city or fortress was besieged, the defenders didn't just stay behind the walls. The defenders would often conduct "sallies", that is Raids against the attacking encampment. These raids could be very damaging and could come at any time. This ability to hit the attacking camp was a vital weapon.
The second reason is that battering rams were just as capable at destroying a section of the wall as the gate. The gate being the most structurally weak portion of the fortifications wouldn't change by bricking up the gates, but it would limit the defenders options.
The 3rd reason is the design of the Gate House itself. The gate house often had 2 sets of gates and the section between the two gates had "Murder-Holes". These were slits in the ceiling and sides where defenders could drop stones, hot sand, boiling water or oil and arrows & bolts.
These sections of fortifications were extremely deadly, so much so that it was actually a rarity for a city or fortress to be taken by storm. Generally an attacking army preferred, if time permitted, to contain the defenders within the fortifications and starve them out. The gates were strong enough to do the job