To be honest, this is why I don't like learning music theory from youtube tutorials and stuff like that. They give you a lot of rules that you're expected to follow without properly telling you why, and people develop an expectation that the rules are concrete and permanent and/or learn information that only makes sense when you learn fundamental concepts that get glossed over.
You can use any note and any chord in any scale, because almost every scale has the potential to play every single note, you just have to change the accidental. C Major contains every natural note (white keys on the piano), so the D chord you're referring to - D Natural Minor - would be called a
diatonic chord - it only uses notes that are found within the scale. However, there's nothing saying that you
can't use D major (D F# A) or D Diminished (D F Ab), for example, if you think it'll sound good.
I recommend everyone go to
musictheory.net and spend a few days really going through the lessons one by one and trying to digest the information in sequence. If you can learn to read sheet music, comprehending theory gets so much easier.