A bastard [ממזר]is born from sex that is with guilt of Karet [כרת]. It has nothing to do with marriage.
An example would be a woman that is married to one man and then has sex with another, or any of the types of karet in Viyakra (Leviticus) 18 and 20. [There is an exception of nida [menstruating'--seeing blood ] who is under penalty of karet and yet one born from a nida is not a bastard ]
There is an opinion of R. Akiva who holds a bastard can come from sex is merely prohibited by a prohibition, .but that is not the law.
Guilt of Karet is a kind of prohibition that gets the death penalty if done on purpose in front of two witnesses or has to bring a in offering if done by accident. [e.g. idolatry]
sex with an unmarried woman is not prohibited at all Tothe Rambam it just i lacking a positive command of getting married. But to most Rishonim it is not prohibited at all.
see Chronicle I chapter 2. verse 46
[But I can see good reasons to be married in term of commitment..That is it tends to reinforce mutual commitment. But it does not make sex holy ]