How liberal are institutions with regard to doing research in a different (unrelated) field than the person's diploma?
You can do research in whatever field you are qualified to do research in, regardless of what it says on your diploma.
Certainly it may be more difficult to convince someone to hire you in a field other than the one your degree is in; but it is possible, if you can show that you are qualified to do research in that field.
For example, if a person with diploma in pure mathematics wants also to do research and programming in IT (specifically in XML), can he do it in his work time?
You are not necessarily restricted to research jobs in the same department as your diploma.
However, research jobs are typically offered for a single area (which may be a multidisciplinary area, but won't be two completely unrelated areas).
You could theoretically (if you are qualified to work in both areas) have a part-time research position in a mathematics department and a part-time research position in an IT department. (Though I would not necessarily advise this.) You cannot, however, have a full-time job doing mathematics research, but do mathematics research part-time and IT research part-time.
Does it makes sense to obtain a second diploma (Is Bachelor enough?) in order to be able to refresh the brain by switching between two different jobs during work time?
Splitting your time between unrelated areas means that you are spending half as much time on research as others in your field (for each field). This makes it more difficult to develop deep expertise/experience in either field.
You can "refresh the brain" by switching between different kinds of tasks within one job - e.g., between creative research, writing research results, dealing with administrative stuff, reading papers, etc. - or by working on multiple projects in the same field.
However, if you are sure you want two different jobs, and you are not qualified to work in the second field without a diploma in that field, then go ahead and get one. The idea of having two unrelated research jobs makes no sense to me, though.