A good way to compare basicity of basic compounds is to draw their corresponding conjugate acids and compare their stability. As you might figured out from drawing resonance forms of compound (2)'s conjugate acid (its protonated form ), the positive charge is going to be shared by the 3 nitrogens in the compound. On the other hand, in compound (4)'s conjugate acid (protonated form) the positive charge is on a single nitrogen. Of course, this gives compound (2)'s conjugate acid higher stability.
Your reasoning about the nitrogen being sp2 makes it less basic in comparison with sp3 nitrogen is correct,however; it only holds true if you were comparing two nitrogens with the only significant difference being the hybridization state, but in some cases, resonance will stabilize or destabilize the conjugate conjugate acid of the base, this is usually have greater impact than hybridization with regard to ranking baisicity of the compounds as in the question presented.
Electronegativity is an important factor in ranking acids/bases,but as I said, it should be used with compounds where the only significant different in the structures is about it (for example, 4 compounds with same structure but only difference is Cl, I, Br, OH at a specific position), in other cases, other factors such as resonance stabilization and aromaticity should be also considered alongside electronegativity.