This is done either because of failure, or to install a different engine, usually one that is more modern, this may make it more powerful and or efficient. Older engines may also have a shortage of spare parts and so a modern replacement may be more easily and cheaply maintained. Swapping to a diesel engine for improved fuel economy is a long established practice, with modern high efficiency and torque diesel engines this does not necessarily mean a reduction in performance associated with older diesel engine swaps. For the particular application of off-road vehicles the high torque at low speed of turbo diesels combined with good fuel economy makes these conversions particularly effective. Older non-electronic fuel injection diesels were well known for their reliability especially in wet conditions.

Is it true that can you put different engines in a car?
yes