How coal energy changed into mechanical energy?

By burning the coal. The stored chemical eneregy is converted to heat energy. That may be used to create steam. Expanding steam pushes a piston or turbine, converting the heat energy to mechanical energy.