It may not have been customary for men to be wearing swords at Elsinore or in fact in any castle unless they were guards. But Shakespeare wanted Hamlet to be wearing a sword so that he could withdraw it when he thought of killing Claudius at his prayers, when he actually did kill Polonius on the spur of the moment, and when he scared his poor mother with it. So this may have been one of the reasons that Shakespeare started his play with the mood of a nation preparing for war. The whole business with Fortinbras may have originated because Shakespeare wanted Hamlet to kill Polonius, and perhaps also to show that he was capable of killing Claudius at any time. If the Danes were expecting to be attacked by Fortinbras, then it would be acceptable for many of them to be wearing their swords. This seems to be the only way it would be plausible for men like Hamlet, and probably Horatio and Laertes, to be armed at all times. Hamlet draws his sword when he comes upon Claudius at his prayers—but this may only have been invented in order to demonstrate to the audience that Hamlet actually did have a sword. This is sometimes called a “plant” in Hollywood parlance. If a weapon is going to be used, the camera will show that weapon beforehand. Hamlet has a sword when his ship is attacked by pirates, but it would be standard practice for men to wear swords when traveling.