Jesus needed to be baptized by John "in order to fulfill all righteousness."
How does one fulfill righteousness?
I think Joseph fulfilled righteousness by staying with Mary even after she became pregnant. He went to bed resolved to do the righteous thing and divorce her quietly. He woke up ready to fulfill righteousness even by doing the unrighteous thing and keep her as his wife.
Here's the difference, as I image it. To be righteous is to follow directions laid out on a map. First you turn left to avoid this sin, then you turn right to avoid that one. When you have done all these things you will have achieved righteousness. To fulfill righteousness you lay the map aside and instead follow the voice directions of your GPS. Turn right here. Turn left here. Avoid traffic by exiting now. Sometimes the voice directions will lead you through the unsavory part of town, but it is all in the pursuit of the end goal.
The end goal for us is, of course, the Kingdom of God. Which is, in my understanding, beyond righteousness for the sake of rule following. Instead it is the fulfillment of righteousness, even to the point of unrighteousness, in order to be obedient to the King.
It would be so much easier to just follow the map, but often the voice of God leads us out into the wilderness, through the bad part of town so that his glory might be revealed.