Mesprit is one of the legendary Pokemon that make up the lake trio. Mesprit, Uxie, and Azelf all appear in Pokemon Brilliant Diamond and Shining Pearl, however, they can't be caught until you've gotten past the climax of the game and defeated the Elite Four. Once that is done, you can begin the journey to capture Mesprit.
After getting the third gym badge, you can go back to Jubilife City and talk to the Poketech company president to get the Marking Map application. You will need this app to track down Mesprit later on. There is no need to get this app before meeting Mesprit for the first time.
Head to the Lake of Truth. You should remember this area from the beginning of the game as the area where you select your starting Pokemon. Use Surf to get to the cave in the middle of the lake. If you have reached the end of the game, when you enter the cave, you will find Mesprit waiting for you inside. This interaction won't last long and Mesprit will run away from you.
With the Marking Map application, you can now track Mesprit's location on the map by opening the application. After Mesprit's run, the Pokemon should appear on Route 205 near Floaroma Town. Head there and keep running back and forth between Route 205 and Floaroma Town until Mesprit is in the same location you are. Use a Repel and head into the tall grass to meet this legendary Pokemon. Mesprit will run at the earliest opportunity, so make sure you have Quick Balls or a Master Ball ready.