Apparently, some people have them despite not being able to afford them simply because they think that having children is "normal" and that being anything other than "normal" is bad. Of course, society is changing, and in many circles the option of choosing to not have children is becoming more and more accepted, making it "normal", so in the future, at least in Western countries, the amount of people who have children simply because "that's what people do" should lessen. There are also the kind of people these days that demand explanations when someone chooses to have kids, as in "why would you want a child? There's already too much of us on this planet/it's expensive/it'll take all your free time!"
And some others know they can't afford it, but not all decisions are made with logic only. They simply want a child, and their emotional needs to be a parent ends up winning. Just like some people know, logically thinking, that they'd be better off in their life without keeping in contact with their abusive parent/sibling/child/partner/friend, but their emotional side cares about that person and wins, causing them to end up keeping that person in their life.
And of course, there are also people who thought they could afford raising a child, but were wrong. Some of them don't realize how expensive it can be, and others do know, but unexpected complications in life, like illness or unemployment, make them have less money than they thought they would, and thus makes affording raising a child harder.