What does “resident” mean in title like “resident mathematician”?
To pick up your example, a resident statistician is somebody who holds a position:


at a research institute (or similar) that does not focus on statistics,
that entails to consult other researchers at the institute on statistical questions.


I have never seen this as an official title or job description; rather the resident statistician is hired as a regular researcher or professor. Some resident statisticians perform their own research, while for others consulting is a full-time job. It may also happen that somebody is hired for other reasons and then morphs into a resident statistician because they turn out to be good at it, nobody else would do it, etc.

I use to describe myself as the resident data analyst of my current life-science research group, because it is good way to characterise (part of) my role in a few words.

Do not confuse this with artists in residence.


  And what are the main subjects where resident is attached to a title? For example, does a resident statistician exist? Or a resident medieval historian?


In my experience, resident statisticians, mathematicians, and similar are the most common, but I also know cases of resident biologists (in a biomathematics group) and physicists (in a quantum-philosophy group). I can imagine that a group investigating historical climate would have a resident medieval historian to investigate historical weather records.