Nobody knows. It started in about 900AD in monasteries (because the monks were the only people technical enough to maintain and play one) and became part of church tradition a few centuries later.
And after a millenium of use, in the late 1980s to early 1990s almost all churches stopped using them.