Not a teacher but a native speaker.
The phrase means to do something simply because you are used to doing it, for no other reason. So in your example the person is smoking partly because they are used to doing so (as they admit in the last sentence).
A habit is a pattern of behaviour or trait you have aquired eg. biting your nails or smoking.
For example if it had been raining for a month solid, you would put on your coat, however when it stopped raining and you put on your coat, you would be doing it 'out of habit' because you had become acustomed to doing so.
Hope this helps, let me know if you need any clarification on anything.