Usually a camera will report an error code when that happens.
By checking with the Internet you can find out what that code means.
Check the LCD when that occurs and see if there is an error code displayed.

A weak battery can cause the problem and a dropped camera can have the same symptom.
When it happens you can usually assist the lens by gently pulling on the lens housing. That often lets the lens lock into place.