How was the inner core formed?
The highly dense inner core is formed under extreme conditions of temperature and pressure.
Owing to attraction towards center,under inverse-square-distance law, the pressure increases with depth towards the center and this indeed increases temperature too.
The temperature at the inner core might be as high as the surface temperature of the Sun.
The density at the center might be six times the density at the top layer..