Is it possible to change the reference clock in a cpu while it is running
As noted in the comment, there is no general answer to this.  The answer is going to be based on your specific case.  Let me, however, show you how to find what you're looking for in an example.
In this case I have taken an excerpt of a datasheet for a part that I'm familiar with, the Microchip (i.e. Atmel) ATxmega128A4U MCU.  Note this page from the document at:
Microchip ATxmega128A4U Datasheet
If you look at the highlighted (in yellow) specification, it says that for this part, you cannot change the input clock period by more than 10% from one clock cycle to the next.  What might happen is not specified but if you are doing it anyway, be prepared for indeterminate behavior.
I do note that the chip itself has internal selections for switching between 32MHz, 2MHz, and 32KHz clocks and there are not stated restrictions on switching these in software.  So I assume that the chip designers have accommodated that somehow.
I'm going to guess that the reason for the 10% limit is that the internal PLL can only track a changing clock period so quickly and if you go beyond 10% up or down, the PLL may lose it's lock.