The nice clean energy level diagram, with the valence band below, the conduction band above, and the well defined band-gap in the middle, is something of an idealization. It's approximately what you'd get if you had a perfect lattice, and only the exact dopant atoms in a nicely even distribution.
Any number of things are going to fuzz up those clean lines. Mostly impurities will be the culprit. The intended dopant atoms are impurities in the lattice that happen to create energy levels near enough to the conduction band that thermal variations are enough to allow electrons to escape from them into the conduction band (N-type) or settle into them and leave a 'hole' to act as a charge carrier (P-type). However, it's just not possible to prevent other, unwanted impurities from getting in, and these can put energy levels anywhere in the gap. Thermal variations aren't enough to let electrons out of (or into) these kinds of levels, hence the name 'trap'.