Multiple factors are considered while giving priority.
Apart from accident relief trains and other emergency trains. IR has got a priority order RAJ Shatabdi SF so on. If two trains belong to same category controller might get precedence to use his ability to allow best possible train to leave ahead with minimal impact on RT trains.
This...
more... my opinion based on my limited knowledge.