- (!A) I was tired because I didn't sleep.
- (2A) I was hungry because I didn't eat.
- (1B) I was tired because I hadn't slept
- (2B) I was hungry because I hadn't eaten
All four of the above sentences are grammatically valid, and quite natural. Any of them may be "right", depending on the context.
The first two (the A group) use a simple past construction, and the B group uses a past perfect construction. That is the difference.
Past perfect form is often used to discuss an event in the past that comes before, or starts before another event, or that continues up to a specified point. The past perfect is formed with a past tense of her verb "to have" (had or hadn't) plus the past participle form of the main verb (usually an -ed form). See this page and this page for more on how ro form the past perfect, and when to use it.
Sentence 1A simply indicates that the speaker did not sleep at some time in the past, probably specified by a previous sentence. Sentence (1B) indicates that the speaker did not sleep prior to some other event, which is probably specified in a previous sentence. The difference between 2A and 2B is precisely teh same about not eating, as opposed to not sleeping.
Update:
In a revision, the OP asks:
can't we say "I was tired because i didn't sleep the night before"?
Yes, one can say that, and it is grammatically valid and quite natural. The forms using "hadn't" are more specialized. Those forms are mostly used to relate one past event to another past event, explicitly or implicitly. To simply describe a single past event, the simple past using "didn't" is the more usual form.