They were caused by the whips, nails and crown of thorns at his crucifixion. Sometimes these marks have also mysteriously appeared on other people. None of them were wounded by actual nails or weapons. St. Francis of Assisi was the first person known to have stigmata. It happened in 1224, shortly before his death.
Nobody is certain how the stigmata appear.
One explanation is that the victims think so much about Jesus' suffering, that their minds create the wounds on their own bodies. Our minds can cause real physical changes on us. Of course, some of the stigmata may be self-inflicted and others may be true miracles.