Assuming you build the computer yourself, open the case remove cpu heat sink and fan clean off thermal paste (read how to clean it off properly from forums in here) and reapply thermal paste (also alot of guides out here) reseat the cpu fan screw everything back together and try again =)
Usually it’s pretty obvious when the fan becomes lose. One of the plastic grommets will have popped off and the fan will look crooked and you will be able to wiggle it around with minimal effort.
If so it needs to be remounted. Remove the CPU fan and inspect the mounting grommets. Are they intact or are they broken and worn? Of broken or worn to the point they wont secure the fan, replace the fan.
something is most likely to overheat and the pc is shutting itself to save the components. go to bios and check your cpu temerature..if its high then remove the heatsink wipe the thermal paste off the heatsink and cpu...apply new thermal paste and install the heatsink (im suspecting you didnt install the heatsink correctly)