Each case is assessed on its individual merits - sadly the medical is usually one of the last things to do before you start work (assuming you get an offer of a job) so you can get a very long way down the chain and be binned at last hurdle.
It would really depend on the nature of the mental health illness. More 'common' health issues such as anxiety or depression would probably not cause an issue. It is something you would declare prior to your medical on your declaration form where they ask you a range of questions before it happens. As already mentioned the medical is at the end of the process though. You mentioned an "operational job" - the railway does have a stricter level of medical if you would be filling a 'safety critical' role which are normally positions that involve the safe movement of trains (e.g. signaller, driver, guard, dispatcher)