This is a gross oversimplification to the point of being untrue.
In addition to what the sibling comment said about asking itself not being illegal, you're allowed to discriminate based on health/disability status all you want if the disability prevents an employee from doing a bona fide job requirement and there isn't any "reasonable accommodation" you can provide for that employee.
For example - if you're a interviewing/hiring for a job that requires the employee to, say, move heavy boxes all day you're going to need to ask that employee "can you lift and move boxes up to 60 pounds?" and you're going to have to reject candidates that can't due to health conditions. Likewise you may have to reject a candidate who is a bad coder even if he has a learning disability.
For the record, what your old manager was doing (directly asking you about your mental health status in a quasi-interview setting) was probably illegal, at least in the US (IANAL). There are pretty strict rules around the kinds of things that employers are allowed to ask prospective employees about, and health (mental or otherwise) is very much on the "not allowed" list.
Employees have a legal right to protection from discrimination along those lines, and companies (no matter how small) most definitely do _not_ have the right to discriminate in that way.