This is Calderon's 17th century Spanish dramatized imitation of an action, making three-dimensional the philosophical question of whether this so-called “real world” is actually some sort of illusion, a “dream” from which we will be awakened some day. The moral question, then, is how should we be acting if this is some sort of test, some revelation about our character, our “nobility” that will be revealed at death?
Segismund is the son of King Basilio and rightful heir to his throne. But because of unfavorable predictions at his birth (he would be violent, unmerciful, and unkingly), he is denied his right to succession to the throne and is imprisoned, with orders to his keeper, Clotaldo, to let him have no human contact. (This is the thematic equivalent of our state, imprisoned in our own human condition.) By a series of coincidences, and accidental contact with humans (thematically equivalent to accidentally catching a glimpse of the other-world currently beyond our view), and the drugging of Segismund (thematically representing a dream inside our "dream"), he is brought into court and does in fact act violently, as predicted. When drugged again and returned to his cell, he thinks he has “dreamed” the court episode, just as we, if given a glimpse of another world, would think we had dreamed it. The play’s strength is in the moral lesson it teaches: that we should always act nobly, as if this life were a dream (or should I say "In case this life is a dream"?) (There are secondary plots, mostly love plots.)