I don't know exactly what model of phone you have, but most smartphones have a proximity sensor which is used to intelligently blank the screen only when it is at your head. Not uncommonly this sensor gets dusty or dirty, causing the issue you describe.