If you only talk to yourself when you are stressed or in your leisure time, it is generally not caused by illness.
However, if you don't communicate with others much except yourself, or you have trouble communicating with others, you need to consider the emergence of mental illness, such as depression and anxiety, which may cause this symptom.