What is causing me to have pain in my jaw muscles. It only hurts at nighttime when laying down. Is it an ear infection?

Jaw Pain. Good day;
Most often jaw muscle pain is triggered by stress. Try to figure out what issues are stressing you and attempt to resolve those concerns. Most patients notice their bite more when they are in a supine position and the dentition is in occlusion. Could have tooth prematurity ; consider a visit to your dentist soon!
Jaw muscle pain. Jaw muscle pain is often related to clenching or grinding of your teeth which may reflect the body's reaction to stress or tension, and may be also associated with misalignment of teeth. See your dentist for an evaluation and possible suggestions to prevent or minimize harmful effects of these habits.
Bruxism? There are some people who clench their teeth and grind their teeth during sleep or unconsciously while under tension. It is also possible to have temporal mandibular joint problems which are positional in nature. Suggest you see a dentist/oral surgeon or ENT doctor and get this problem solved.