What chords can you use these scales with? If a song is in D major could you use the d major pentatonic or b minor since that is the relative key?
To expand on what D said, you can play the "B minor pentatonic box" over a song in D major. However, the root will be D, not B, so it will be called the D major pentatonic, not B minor. Root notes determine the scale, not the position or pattern.

To expand on what edg said, you would typically use D major pentatonic over D major progressions and B minor pentatonic over B minor progressions. This should make sense. However, to achieve a bluesy sound, the D minor pentatonic is often played over D major progressions. The progression will generally make use of the b7 note and chord rather than the maj7 ie it will use C notes and C chords rather than C#. A good progression to use Dm pentatonic over is D C G C. This is what is going on in Bad Company's "Feel Like Makin' Love."
Quote by ouchies
But only if its a dominant chord, chord, right?

Yes, I believe he meant using a minor pentatonic scale over a dominant chord featuring the same root.
Quote by ouchies
But only if its a dominant chord, chord, right?
It doesn't have to be. The b7 can be implied by other chords or your solo. You just have to be in a position where nothing says you shouldn't play Dm pent, such as a C# note.
You could use the B minor pent shape or the notes in B minor pentatonic, but their functions are entirely different then they would be if you were playing in B minor. However, D major pent does have the same notes, just know that if you do "play" B minor over D major, it is D major.