I'll use my own box labelling so that the method is shorter to describe.
Step 1: First I'll remove the labels, then pick any three boxes and test them. Whichever of the three boxes is the median I'll label B, and the other two boxes are A and C.
Pick B and the two unlabelled boxes. If the median of these is again box B, then we are done - B must be the median. If the outcome is another box, I'll label that box E, and the other unlabelled box becomes D.
Test A, C, and E. The outcome of this test is the median of the five boxes.
If the first two tests have the same answer B, then that must be the median because B must have A,C on either side and also D,E on either side. So it has 2 boxes on either side and is therefore the median.
If second outcome is E, then median cannot be B (B has D, E, and one of A,C on one side) and also not D (it has B, E on one side, and beyond B there must also be one of A or C).
Note also that whichever side of the median B lies, one of A or C must lie beyond it, leaving no room for anything else. This means that B and D lie on different sides of the median. Removing them both will not change the median, so that the median must be whichever one of A, C, E lies in the middle.
Proof of optimality:
Suppose there was a method using only two steps. The two steps must involve all 5 boxes (any untested box could be the median but you would never know it from the results of your tests on the other boxes). Therefore the two tests must have exactly one box in common. If the shared box is the median in one of the two tests, then with appropriate box labelling it matches the first two steps in the solution above. After those two steps, any of A, C, E could still be the median (e.g. ABCDE, CBEDA, CBAED). Regardless of which of the three boxes from the first test you choose to reuse in the second test, it is possible for the outcome of the second test to be such that the shared box is the median in only one of the tests. So two tests are not guaranteed to be sufficient.