If I understand correctly, you are asking
Why does the Night's Watch have Rangers? Instead they could stay
behind the safety of the Wall & protect the realm
To answer this question, you first have to know what Rangers in a military establishment are. What is their purpose & what is their value to the overall success of the defense forces.
As stated in the Wikipedia
Rangers were full-time soldiers employed by colonial governments to
patrol between fixed frontier fortifications in reconnaissance
providing early warning of raids. In offensive operations, they were
scouts and guides, locating villages and other targets for taskforces
drawn from the militia or other colonial troops.
Here is a detailed article in How Stuff Works on how the Army Rangers work.
The Rangers are known for their skill at remaining undetected in a
war. If you're in a combat situation and you see a Ranger, most likely
he's already spotted you. There's no telling how long he's been
observing you, and what's more, by the time you detect a Ranger,
you're probably too late.
Their value to the defense forces
They conducted small-scale invasions in Algeria, Tunisia, Sicily,
Italy and France, breaking through enemy lines and opening the way for
larger forces to enter behind them.
So to sum up, Rangers are trained in Guerrilla warfare tactics to navigate, gather intelligence, neutralize & defend against enemies in the most hostile terrains & dense forest. Sounds familiar
Returning back to the Wall, the wildling army was growing (restless & in numbers) day by day.
The number of insurgency attempts were also increasing. Hence, the Night's Watch had to have a special Rangers unit among them to neutralize the threat before it comes down on them with full force.
Remember earlier in season 1 when Jon asks Benjen to take him along for ranging but Benjen refuses. Jon was a brilliant swordsmen but he was no Ranger as yet. So wasn't Waymar Royce in the prolouge of GoT.
As a military strategist & a Lord Commander it was the right choice for Mormont to lead 300 men beyond the Wall to kill the important Wildling leaders. But as Ser Alliser wisely stated in the latest episode
"Leadership is all about getting second-guessed by every clever little
twat with a mouth. But if a leader starts second-guessing, that's it
That's the end."