Using the idea of https://tex.stackexchange.com/a/394924/305075 I use execute at end picture to draw the ellipses in tikz-cd diagrams. The names of the nodes for the ellipse to fit are of the form tikz@f@1-1-1.
The result of the second application of that idea shows that there seems to be a kind of interference between the two diagrams. As if in the second diagram the positions of the nodes of the first are used.
I tried to rename the names to something like tikz@g@1-1-1 (see the g instead of the f) but without success.
My main question, as in the title: How to put ellipses around nodes in tikz-cd diagrams several times in one document?
Second question: can we rename the tikz@f@1-1-1 to tikz@g@1-1-1 where the g is of course just an example?
At the end, I like to draw diagrams of several categories with morphisms and functors. The objects belonging to the same category shall be grouped by putting an ellipse around them. One ellipse per category. The example I have given is much simpler in order to focus on the problem.
I try this:
\documentclass[a4paper]{amsart}
\usepackage{tikz}
\usepackage{tikz-cd}
\begin{document}
\usetikzlibrary{shapes.geometric,fit}
\tikzset{
dashellipse/.style={ellipse,draw,dashed,inner sep=0pt,blue,fit={#1}}
}
\begin{equation}
\begin{tikzcd}[
name=jk,
execute at end picture={
\node[dashellipse=(tikz@f@1-1-1)(tikz@f@1-1-3)]{};
}
]
X && Y
\end{tikzcd}
\end{equation}
\begin{equation}
\begin{tikzcd}[
name=mycustommatrix,
execute at end picture={
\node[dashellipse=(tikz@f@1-1-1)]{};
}
]
X
\end{tikzcd}
\end{equation}
\end{document}


tikzcd; your example does not provide any clue. In case you only need nodes sitting in an ellipse, then you can use thefitlibrary. It was conceived exactly for this job. – Daniel N Sep 30 '23 at 13:00