You are referring the end of scene v, when Peter and the musicians are joking about what songs to play. These men are not involved in the death of Juliet, or with the Capulet family, and so it is not innappropriate for them to be joking at this time. Shakespeare includes the exchange for comic relief, which is needed in a dramatic work to separate out the moments of suspense and tragedy. If the whole play was tragic, with no breaks between the serious scenes, then by the last act the audience would be desensitized. The deaths of Romeo and Juliet would not be more impressive than anything that came before because the audience would be overloaded. However, when comic relief is added, the audience has a chance to relax. After the drama of Act IV, the audience needed to relax so that it could be appropriately surprised and horrified by the events of Act V.