Why is Google still indexing those links?
It's because Google Bot found those link on your site at some point in time and that's why it indexed it. Google Bot doesn't make up URLs so it must of found it on your website. If Google indexed something once, it will come back and revisit it, even if the destination resource doesn't exists or the original link to it doesn't exist on your website anymore. My guess is that it was a programming mistake because it's easy to make that mistake, especially if your have do URLs in PHP.
Does this affect SEO?
Not really, links resulting in 404 errors don't affect your SEO.
However, I would be much more concerned about the 70+ of your website ZOMBIES pages. Basically, Google crawler started indexing your website's search controller (yourwebsite.com/search). If you type into Google "site:yourwebsite.com", it will show you all indexed pages for that domain. See your Zombie pages here.
How to fix it?