Calcium hydroxide is used in deep cavities in order to:
A deep caries excavation close to the pulp, which may result in either an undetected pulpal exposure or a visible pulpal exposure, should be covered with a calcium hydroxide liner that can stimulate formation of dentin bridges (reparative dentin) over the exposure.
If used, the calcium hydroxide liner should always be covered with a glass ionomer or resin-modified glass ionomer liner before the tooth is restored.

Sturdevant's Art and Science of Operative Dentistry. Edition 6. Page: 83
Form dentin bridge
To kill microorganism
To cause necrosis
As a base under restoration