People kill for all kinds of reasons. There's crimes of passion, self defense and sadly, where I live they tend to use it as a gang initiation. As for getting caught, some believe that not only are they above the law, but that they can also outsmart it.
Why do people who kill other people know that they're gonna go to prison? So what's the point of killing someone? They know they will get caught.
Sometimes they think that it is worth it, that they hate the person or want revenge so badly that they would rather be in prison, knowing the person is dead, than be out of prison, but the person is alive and often they don't think they will be caught.
Desperation perhaps. Panic. Not thinking straight.
They don't stop and think of consequences