Would you believe that the technical reason behind this is PHYSICS. Booking a seat in a train is far more different than booking a seat in a theatre. Theatre is a hall, whereas train is a moving object. So safety concern is very high in trains. Indian railways ticket booking software is designed in such a way that it will book tickets in a manner that will distribute the load evenly in a train.
An example to make things more clear : Imagine there are sleeper class coaches in a train numbered S1, S2 S3... S10, and in every coach there are 72 seats.
So when some one first books a ticket, software will assign a seat in the middle coach like S5, middle seat numbered between 30-40, and preferably lower berths (Railways first fills the lower berths than upper one so as to achieve low centre of gravity.)And the software books seats in such a way that all coaches have uniform passenger distribution and seats are filled starting from the middle seats (36) to seats near the gates i.e 1-2 or 71-72 in order from lower berth to upper.
Railways just want to ensure a proper balance that each coach should have for equal load distribution.
That is why when you book a ticket at the last, you are always allotted an upper berth and a seat numbered around 2-3 or 70, except when you are not taking a seat of someone who has cancelled his/her seat.
What if the railways book tickets randomly ?
A train is a moving object which moves around at a speed of around 100km/hr on rails.So there are a lot of forces and mechanics acting on the train. Just imagine if S1, S2, S3 are completely full and S5, S6 are completely empty and others are partially full. When the train takes a turn, some coaches face maximum centrifugal force and some minimum, and this creates a high chance of derailment of the train.This is a very technical aspect, and when brakes are applied there will be different braking forces acting at each of the coaches because of the huge differences in weight of coach, so stability of train becomes an issue again.
Good information worth sharing, as often passengers blame the Railways citing inconvenient seats/ berths allotted to them.