Virgil is not sent away or punished: the poem takes him off the stage because the reason he represents reaches, there, the end of its reach. He takes his leave without a farewell at the top of the stairs in canto XXVII, and when Beatrice arrives, in canto XXX, Dante turns to tell him and the place is empty.
His departure is prepared. At the wall of fire, Virgil tries three arguments of reason and none moves Dante; only the name of Beatrice makes him enter. The next morning, on the last step, the master says that he has brought him that far "with wit and with art" and that from now on Dante's pleasure must be his guide. He gives Dante's will three adjectives, free, upright and sound, and crowns and mitres him over himself. After that he says no more, although he goes on with him through the next two cantos.
When Beatrice appears, Dante feels the old love, turns to tell Virgil as a child runs to his mother, and does not find him. The guide's name, repeated three times with a new title each time, measures the loss. A voice then tells him not to weep for Virgil yet, because it is fitting for him to weep for another sword.
Virgil himself had explained the reason for the limit, being a pagan: reason reaches as far as it sees, and from there on it is a work of faith. Dante had already told Forese that he would go with him as far as the place where Beatrice would be, and that there it would be fitting to stay without him.