I assume, that you after to have two parallel pictures with own captions. This you can simply achieved by putting pictures in tabularx table:

In the following MWE (Minimal Working example) is preserved their inserting in document using center environment and for caption are used \captionof {figure}{<caption text>} defined in caption package or you can use small capt-of package:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,
shapes.geometric}
\usepackage{caption}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{center}
\tikzset{ellipsenode/.style = {% common style for nodes
ellipse, draw, thick, text width=2em, align=center, inner sep=2pt},
node distance = 21mm and 7mm
}
\begin{tabularx}{\linewidth}{@{} C @{\hspace{30mm}} C @{}}
\begin{tikzpicture}
\begin{scope}[nodes=ellipsenode]
\node (1) {$y_{1}$};
\node (2) [above right=of 1] {$y_{3}$};
\node (3) [below right=of 2] {$y_{2}$};
\node (4) [above left=of 2] {$y_{5}$};
\node (5) [above right=of 2] {$y_{4}$};
\end{scope}
%
\draw (1) -- (3) -- (2) -- (1)
(2) -- (4) -- (5) -- (2);
\end{tikzpicture}
\captionof{figure}{Caption of left diagram}
\label{fig:diagram-left}
&
\begin{tikzpicture}
\begin{scope}[nodes=ellipsenode]
\node (1) {$y_{1}$};
\node (2) [above right=of 1] {$y_{3}$};
\node (3) [below right=of 2] {$y_{2}$};
\node (4) [above left=of 2] {$y_{5}$};
\node (5) [above right=of 2] {$y_{4}$};
\end{scope}
%
\draw (1) -- (3) -- (2) -- (1)
(2) -- (4);
\end{tikzpicture}
\captionof{figure}{Caption of right diagram}
\label{fig:diagram-right}
\end{tabularx}
\end{center}
\end{document}
However, if you like to enable to float figures to the best position in the document, you only need to replace center with figure and use standard captions commands:
% preamble
\begin{figure}[ht]
\tikzset{ellipsenode/.style = {% common style for nodes
ellipse, draw, thick, text width=2em, align=center, inner sep=2pt},
node distance = 21mm and 7mm
}
\begin{tabularx}{\linewidth}{@{} C @{\hspace{30mm}} C @{}}
\begin{tikzpicture}
\begin{scope}[nodes=ellipsenode]
\node (1) {$y_{1}$};
\node (2) [above right=of 1] {$y_{3}$};
\node (3) [below right=of 2] {$y_{2}$};
\node (4) [above left=of 2] {$y_{5}$};
\node (5) [above right=of 2] {$y_{4}$};
\end{scope}
%
\draw (1) -- (3) -- (2) -- (1)
(2) -- (4) -- (5) -- (2);
\end{tikzpicture}
\caption{Caption of left diagram}
\label{fig:diagram-left}
&
\begin{tikzpicture}
\begin{scope}[nodes=ellipsenode]
\node (1) {$y_{1}$};
\node (2) [above right=of 1] {$y_{3}$};
\node (3) [below right=of 2] {$y_{2}$};
\node (4) [above left=of 2] {$y_{5}$};
\node (5) [above right=of 2] {$y_{4}$};
\end{scope}
%
\draw (1) -- (3) -- (2) -- (1)
(2) -- (4);
\end{tikzpicture}
\caption{Caption of right diagram}
\label{fig:diagram-right}
\end{tabularx}
\end{figure}
I took a liberty to change your diagram code:
- defined are common nodes style for both pictures,
- by using
positioning TikZ library nodes are positioned relative to each other.
- nodes are grouped by
scope
- connections between nodes are drawn in two loops
Now the code slightly shorter.
tabularenvironments with yourtkizpictureenvironments. – leandriis May 22 '21 at 11:38