Initially, Alfonso actually encouraged the marriage in private. My understanding (and I look to others to correct me if I get this wrong) is that the Spanish Constitution forbade the monarch from approving a marriage without the consent of his government. The then-prime minister was not willing to give consent because Beatrice was not willing to convert to Catholicism (she did convert eventually). The couple thought that Alfonso would not object if they married outside of Spain, which they did do with the help of the Duke of Coburg. However, under pressure from his government, Alfonso stripped his cousin of his titles and positions. I recommend the book Ena and Bee: Queen Victoria's Spanish Granddaughters by Ana de Sagera for a full account.
Previous Message
Why did King Alfonso XIII of Spain oppose his cousin's marriage to Princess Beatrice of Edinburgh?