A pet is something that receives particular favor, as in “teacher’s pet.”
A peeve is an irritation that one feels, real or perceived.
Hence, a “pet peeve” is a particularly welcome irritation, giving someone reason to complain. If you have enough of them, sort of a “herd of pet peeves,” you’ll find yourself standing all by yourself with just your “pets” to keep you company. Nobody enjoys a chronic complainer.