It depends on the case. If you can remove the side panel and easily get to the CPU backplate to remove it, then you probably can do the swap with the motherboard in the case. It is probably easier to do it with the motherboard out of the case.
Both @ScrewySqrl and I are technically correct. If you don't have to change the backplate then you can usually do it in the case. If you HAVE to change the backplate then it depends on the case. Some cases have a hole in the motherboard tray that lets you access the CPU backplate.