It can be achieved using counterwithout
EDIT. A couple of remarks.
The package chngcntr
is required before Apr 2018 of LaTeX (see LaTeX2e News Issue 28).
\counterwithout*
has an unstarred version \counterwithout[format]{counter}{within counter}
, which automatically removes within counter
if the optional argument is omitted; particularly, in the solution, chapters would no longer appear as a part of section numbering. If this is the desired effect, then \counterwithout
should be used, instead.
For more information see the reference: source2e (the section "ltcounts.dtx" p. 400). Also, there is a website Counters on Overleaf, which provides some explanation with a few examples.
\documentclass{report}
%\usepackage{chngcntr} % Before Apr 2018 LaTeX
\counterwithout*{section}{chapter} % Section numbering remains unchanged
% \counterwithout{section}{chapter} % Redefines section numbering
\begin{document}
\chapter{A}
\section{X}
\section{Y}
\chapter{B}
\section{Y}
\section{Z}
\end{document}
\section{Third section}
without changing the counter in any way. Please clarify.\thesection
and remove chapter numbers from it or non-starred version and keep the numbering unchanged. I also pointed to two places with more information about counters.