One of the reasons physicists love the Dirac bra-ket formalism is precisely because it avoids the less physically intuitive mathematical machinery of Functional Analysis, but it is in this branch of mathematics that you'll find your answer. So here's an outline of how to make sense of the whole 'resolution of the identity' thing in both the discrete and continuous case without using the Dirac shortcuts...
Let ##\mathcal A## be an arbitrary (real-valued) observable (Energy, Position, Momentum, or whatever). For any subset ##\Delta \subset \mathbb R## of the real line we can ask the question: "Will a measurement of ##\mathcal A## land in ##\Delta##?". This question is itself an observable which (having only the values 0 or 1) is represented by a projection operator we label ##P(\Delta)##. Now all the information concerning ##\mathcal A## is housed in the family ##P(\Delta)## (for all subsets ##\Delta##). This family is called the Projection Valued Measure (PVM) of ##\mathcal A##.
Obviously we must have ##P(\phi)=\mathbb O## and ##P(\mathbb R)=\mathbb I##, but we also get that ##P(\bigcup \Delta_i)=\sum P(\Delta_i)## for disjoint subsets ##\Delta_i##. This in turn means that if we partition the real line by ##\mathbb R=\bigcup \Delta_i## then we have ##P(\bigcup \Delta_i)=P(\mathbb R)=\mathbb I##, which is why we call the family ##P(\Delta)## the resolution of the identity (corresponding to ##\mathcal A##). (Intuitively, the resolution of the identity follows from the simple fact that the outcome of a measurement must turn up somewhere in ##\mathbb R##.)
What does all this abstract stuff have to do with your example? Well, in the nice simple case where we have an observable with a pure discrete spectrum, ##{n=0,1,2,...}##, the only ##\Delta##s that matter are those of the form ##\Delta_n=\{n\}## (since the PVM vanishes outside the spectrum by definition). This leads to the result: ##P(\mathbb R)=P(\{0\})+P(\{1\})+P(\{2\})+\cdots =\sum P(\{n\})=\mathbb I##. Using the Dirac notation ##|n\rangle\langle n| := P(\{n\})##, this just says ##\sum |n\rangle\langle n|=\mathbb I##.
What about the continuous case? Well, define ##P(\lambda):=P(\left(-\infty,\lambda\right])##. Then we can set up a well-defined integral (known as a Stieltjes Integral) with respect to the measure ##dP(\lambda)##, and we find that not only does ##\int dP(\lambda) = \mathbb I## (resolution of the identity) hold in the continuous case, but in the discrete case it yields ##\int dP(\lambda)=\sum P(\{\lambda_i\})=\sum|\lambda_i\rangle\langle \lambda_i|##.
So that's how it works in pure mathematics. And that's why physicists use the Dirac notation instead ;-)