When a person dies he or she attains a ghost-like state called a Preta. To remove this preta-hood the family members of the deceased person are required to do the funeral rites as prescribed. Only then the dead are relieved from the ghost-like state and attains the state of a Pitri (Mane).
For one dying of a disease of the hair one should perform eight
Krichchhas. According to this regulation one should perform the
funeral rites for them. (49)
Thereupon being freed from the condition of a preta (dead) the gratified Pitris (departed manes) grant sons, grand-sons, longevity,
health and wealth. (50)
Here ends the [account of the] : fruits [of various] acts given by
S'atdtapa to his disciple S'arabhanga accosting him with humility,
Satatapa Smriti's last chapter.
The above verses are the last few verses among the ones that are describing how to do Shraddha for persons who have died in different circumstances.
Unless the Sapindakarana Sraddha is performed, the dead person roams around nearby the place where he or she has died. Until that Sharddha is performed the dead person is called a preta or ghost.
So, people for whom proper funeral rites have not been performed will have the chance of remaining as ghosts.
Apart from that, persons who have committed suicide or who had violent deaths have the chance to become ghosts for a long long time. Because for such deaths funeral rites are recommended not to be done.
[The offering of] water and funeral cakes [and the performance of]
S'rdddha for the great sinners and for those who commit suicide, do
not at all reach [them] but are stolen by the Rakshasas. (175)
However, even in cases of such violent and unnatural deaths, some other scriptures prescribe some remedies like performance of Narayana Bali etc.