Why e is pronounced differently in de (的, 地) and ye (也,夜)?
Systems designed to represent pronunciation and to be practical at the same time don't have a 1:1 mapping between spoken sounds and written symbols. Or in other words, each sound can be represented using many symbols, or perhaps more commonly, each symbol is used to represent more than one sound. There are countless examples of this in other languages, of course.

The only exception is IPA (International Phonetic Alphabet), where the goal is to use one symbol to represent one sound, but this is hardly practical and would never be adopted as the standard way of writing a language for non-linguists.

Pinyin certainly does not have a 1:1 mapping between sounds and letters. Indeed, looking at the individual letters is the wrong way to approach the question, but more about that later. In Pinyin, there are plenty of examples where one letter can stand for numerous sounds, and you have identified one of them: e

e can be pronounced in three different ways (or four if you want to be picky):


First, when it’s the only vowel, it is a close-mid back vowel [ɤ]. This is the sound in 饿 (hungry) or 哥 (older brother), for example.
Second, following an i, such as in lie, die or xie, it becomes a close-mid front vowel [e] instead. This is the sound you're asking about, e.g. 夜 (night). Note that the final -ie is spelt ye when there's no initial.
Third, before the nasals -n and -ng, it becomes central vowel [ə], for example in 冷 (cold). A short version of this is pretty close to the sound used when the syllable is reduced, which is the case in your 的 and 地.
Fourth, in some analyses, the e in e.g. mei and mie are treated as different sounds, with the first using [e] as we have already discussed, and the second [ɛ].


Please note that the spoken sounds of course come first, and the writing of those sounds comes afterwards. Saying "e is pronounced like this" is not really the right way to approach the problem; a better way of looking at it would be "this sound is written using the letter e", which is simultaneously true for a number of sounds (four in this case).

I normally advise students to think of Mandarin pronunciation in terms of initials and finals, which is the traditional way of breaking down syllables in Mandarin. I don't recommend this just because it's traditional, though, but because it helps you stop thinking about how e is pronounced.

There are only roughly 40 finals in Mandarin. Learn that the final -ie is pronounced in one way, and that the finals -en and -eng are pronounced in other ways instead. Those are different finals and should be treated differently. Yes, they all contain e, but that mostly leads to confusion, although it is very convenient to type. Yes, it will take you longer to learn, but it will lead to less confusion and hopefully better pronunciation.

If you're curious about other learner-related problems with Pinyin, such as other cases where one letter stands for many sounds (i is the most obvious example because the sounds are completely different), I've summarised the important ones here: A guide to Pinyin traps and pitfalls: Learn Mandarin pronunciation, which also contains some audio samples.