To be able to define the use of allusion in a text, one first needs to understand what an allusion is. An allusion is, according to eNotes,
a reference, usually brief, often casual, occasionally indirect, to a person , event, or condition thought to be familiar (but sometimes actually obscure or unknown) to the reader.
Therefore, the allusion made to King Cophetua and the beggar maid, in Romeo and Juliet, is meant to refer to the legend of the Medieval king who falls in love with a woman beneath him (in regard to royal blood). Cophetua is a noble, a king, who has romantic feelings for a woman he should not love. His love is so strong for her that he swears he will have her or commit suicide.
This allusion is meant to serve two purposes: foreshadow Romeo's suicide and the forbidden love between him and Juliet.Without the knowledge of the story of Cophetua, one would miss the foreshadowing and the setup of the play.
On a side note, Romeo and Juliet is not the only Shakespearean play which uses the allusion to King Cophetua and the beggar maid. He, assumedly, was enamored by the story given that he mentioned the pair in two histories (Henry IV and Richard II) and one comedy (Love's Labour's Lost).
In Act 2, scene 1 of William Shakespeare’s Romeo and Juliet, Mercutio, calling aloud to summon Romeo, takes a moment to mock Cupid, the proverbial god of love:
Speak to my gossip Venus one fair word,
One nick-name for her purblind son and heir,
Young Adam Cupid, he that shot so trim,
When King Cophetua loved the beggar-maid!
The recent Cambridge edition of the play substitutes “Abraham” for “Adam,” noting that “Adam” alluded to a famous archer and arguing that “Abraham” alludes to a noted beggar who cheated the public by pretending to be crazy.
In any case, the allusion to King Cophetua being shot by Cupid and thus loving a beggar-maid remains. This apparently alludes to a popular ballad of the time. No copy of the version of the ballad to which Shakespeare alludes seems to have survived; a more toned-down ballad on King Cophetua was printed in 1612, too late for that version to have influenced Shakespeare.
Basically, the legend of King Cophetua (a legend also preserved in at least one medieval romance) tells the story of an African king who had no interest in women until he spotted a poor beggar woman in the streets. He instantly fell in love with her, despite their great differences in class and power. The story of King Cophetua, then, exemplifies the power of Cupid to quickly plunge people into instant feelings of “love.” Mercutio is mocking this kind of irrationality.
The ballad printed in 1612 – probably influenced by the one that influenced Shakespeare – emphasizes Cophetua’s attempts to resist his initial feelings for the beggar maid but his eventual submission to them.