Motivating example:
Given a ring, we can construct its lattice of ideals functorially
(with morphisms mapping to the preimage maps on ideals).
Next, we may flatten this category of lattices, obtaining a category
of pairs $(R,I)$ with morphisms $(R,I)\to(S,J)$ being morphisms $f:R\to S$
such that $I=f^\*J$.
Finally, this category maps back to rings by sending $(R,I)\mapsto R/I$.


The idea of this construction is to clarify the preservation of some properties
of ideals by functoriality. Admittedly, this may be using a sledgehammer where
a mere hammer might suffice, but...
$
\DeclareMathOperator{\Ob}{Ob}
\DeclareMathOperator{\S}{\mathcal{S}}
\DeclareMathOperator{\Hom}{Hom}
\DeclareMathOperator{\Ring}{\mathbf{Ring}}
$


The problem is the flattening step moving from a dependent sum of lattices $\sum\_{r\in\Ring}I(R)$ to the set $\{(R,I)\mid I\in I(R)\}$.
It is unclear how to formulate it functorially.


Abstractly speaking, the question becomes:
Consider a subcategory $\mathcal{S}\subseteq\mathbf{Cat}$.
We can flatten $\S$ to $F(\S)$, losing its object structure,
by setting
$$\begin{align}
\Ob(F(\S))&=\biguplus\_{S\in\Ob(\S)}\Ob(S)\\
\Hom\_{F(\S)}(x,y)&=\Hom\_S(x,y)\quad x,y\in S\in\Ob(\S)\\
\Hom\_{F(\S)}(x,y)&=\{F\mid F\in\Hom\_{\S}(S,T), F(x)=y\}\quad x\in S,y\in T; S,T\in\Ob(\S)
\end{align}$$
However, it is unclear how to formulate this as a functor from $\S$.


Side question: $n$-category theory seems to focus only on categories whose $\Hom$s are categories. This situation seems to suggest that it is interesting to consider categories whose *objects* are themselves categories, i.e. subcategories of $\mathbf{Cat}$.
At the very least, it is an elementary exercise that some algebraic structures may be considered as categories with certain properties/structure, motivating such inquiry.



Flattening categories
The construction you’re describing can be seen as the **[Grothendieck construction](https://ncatlab.org/nlab/show/Grothendieck+construction)**, turning the functor $\newcommand{\op}{\mathrm{op}}I : \mathrm{Rng}^\op \to \mathrm{Cat}$ into the total category $\int I$ (what you’ve called the *flattening*) with its projection functor $\pi\_1 : \int I \to \mathrm{Rng}$.


Generally, the Grothendieck construction is (one direction of) a correspondence between pseudofunctors $\newcommand{\C}{\mathcal{C}}\C^\op \to \newcommand{\Cat}{\mathrm{Cat}}\Cat$ and [Grothendieck fibrations](https://ncatlab.org/nlab/show/Grothendieck+fibration) over $\C$ (that is, functors into $\C$ satisfying a certain lifting property), for any category $\C$.


Regarding your second question, on categories whose objects are themselves categories: I think most category theorists would be unlikely to phrase it that way, since a property defined literally in terms of what the objects *are* is categorically rather unnatural (not invariant under equivalence, for instance, or even isomorphism). But a categorically congenial version of the same idea is to consider (2-)categories equipped with a (2-)faithful (2-)functor to $\Cat$, thought of as being (2-)categories whose objects are categories equipped with some kind of extra structure (or just satisfying some extra property, if the functor is moreover faithful); I’ve heard these called *concrete 2-categories*, by analogy with [concrete categories](https://ncatlab.org/nlab/show/concrete+category), categories whose objects may be seen as *sets* with extra structure.


