The modern periphrastic passive construction (ser + participle) comes from Latin, although at first it was used as a passive preterit: amātus sum = "I was loved, I have been loved", and was then reanalyzed as present tense (soy amado = "I am loved").
The reflexive with se also comes from Latin, where its use was broadened to include middle or mediopassive voice. The so-called pasiva refleja was already well established in medieval Spanish. This and the periphrastic construction were developed, according to Félix Sepúlveda Barrios, in response to the loss of the synthetic Latin passive (amor = "I am loved").
Some studies do point out that evidence of a truly passive interpretation of se-phrases in Latin is lacking, and that the medieval Spanish pasiva refleja was almost always used with non-agentive subjects (se hacen cosas) while agentive subjects, if the intention was to show actual passive voice, preferred the periphrastic construction.
In any case this was eventually changed. Says a study about 15th century Spanish:
Todos los gramáticos del español actual son unánimes a la hora de
señalar que el español prefiere la construcción activa a la pasiva, y
que la forma con ser ha visto disminuido su empleo frente al aumento
creciente de la pasiva refleja.
That is: grammarians unanimously point out that Spanish prefers the active to the passive, and that the [periphrastic] form with ser has seen its use diminish before the increased use of the pasiva refleja.
In 15th century Spanish literature the periphrastic form appears most often, but this seems to be for stylistic reasons having to do with the recovery of forms closer to classical Latin. In popular speech the pasiva refleja must have been the most common one. (The author says this may have to do with the fact the Spanish lost the compound tenses conjugated with ser, as found still in other Romance languages like French and Italian, in favor of a conjugation using only haber as auxiliary. The forms with auxiliary ser, like soy llegado, were syntactically similar to the periphrastic passive; as the former lost currency, so did the latter. Today we say he llegado = "I have arrived", while French still says je suis arrivé = "I am come".)
By the 17th century the pasiva refleja and the periphrastic passive construction were employed more or less as in modern Spanish. Sepúlveda Barrios studied texts in the "journalistic" style and in the "colloquial" style of theater, and found that the pasiva refleja won out in both, though much more markedly in the colloquial style. This seems to confirm the trend.
As of today, it is widely accepted that the periphrastic passive is often avoided in speech and informal registers, and most often found in technical, legal or otherwise formal writing. This does not mean that the periphrastic passive is either 1) to be avoided or 2) on its way to extinction. It does mean that it should be avoided by students of Spanish in informal speech, as it would sound stilted or unnatural.