\makeatletter
% With older LaTeX-releases uncomment the following line:
%\RequirePackage{xparse}
\ExplSyntaxOn
\@ifdefinable\MapCommaListToMacro{%
\let\MapCommaListToMacro=\clist_map_function:nN
}%
\ExplSyntaxOff
\@ifdefinable\stopromannumeral{\chardef\stopromannumeral=`\^^00}%
\newcommand\unexpandedlocalsetcounter[1]{%
\unexpanded{\localsetcounter{#1}}{\number\value{#1}}%
\def\expandafter\noexpand\csname theH#1\endcsname{\csname theH#1\endcsname}%
\def\expandafter\noexpand\csname the#1\endcsname{\csname the#1\endcsname}%
}%
\newcommand\unexpandedadjustcounter[1]{%
\def\expandafter\noexpand\csname theH#1\endcsname{\csname theH#1\endcsname}%
\def\expandafter\noexpand\csname the#1\endcsname{\csname the#1\endcsname}%
}%
\newcommand\unexpandedsetcounter[1]{%
\unexpanded{\setcounter{#1}}{\number\value{#1}}%
}%
\@ifdefinable\localsetcounter{%
\DeclareRobustCommand\localsetcounter[2]{%
\csname c@#1\endcsname=#2\relax
}%
}%
\@ifdefinable\localstepcounter{%
\newcommand\localstepcounter[1]{%
\advance\csname c@#1\endcsname by 1 %
}%
}%
\newcommand\PassFirstToSecond[2]{#2{#1}}%
\newcommand\Exchange[2]{#2#1}%
%
% If this was for a package, checking whether stack-macro is defined
% could be implemented for the sake of error-checking.
\NewDocumentCommand\NewStack{m}{\newcommand#1{}}%
\NewDocumentCommand\FlushAndClearStack{m}{#1\global\let#1\empty}%
\NewDocumentCommand\AppendToStack{mm}{\xdef#1{\unexpanded\expandafter{#1#2}}}%
\newcommand\StuffAndCountersToStack[4]{%
\@bsphack
\begingroup
\protected@edef\@tempa{\MapCommaListToMacro{#3}{\unexpandedlocalsetcounter}}%
\MapCommaListToMacro{#2}{\localstepcounter}%
\protected@edef\@tempb{\MapCommaListToMacro{#2}{\unexpandedadjustcounter}}%
\expandafter\endgroup\expandafter\PassFirstToSecond\expandafter{%
\romannumeral
\expandafter\Exchange\expandafter{\expandafter{\expandafter\begingroup
\romannumeral\expandafter\expandafter\expandafter\stopromannumeral\expandafter
\@tempa\@tempb#4}}{%
\stopromannumeral
\begingroup
\protected@edef\@tempa{\MapCommaListToMacro{#3}{\unexpandedsetcounter}}%
\expandafter\endgroup\expandafter\Exchange\expandafter{\@tempa}%
}%
\endgroup
}{\AppendToStack{#1}}%
\MapCommaListToMacro{#2}{\stepcounter}%
\@esphack
}%
%=== \VerbatimToScantokensStuffAndCountersToStack ========================
\NewDocumentCommand\VerbatimToScantokensStuffAndCountersToStack{mmm}{%
\@bsphack
\begingroup
\catcode`\^^I=12\relax
\InnerVerbatimToScantokensStuffAndCountersToStack{#1}{#2}{#3}%
}%
\begingroup
\def\InnerVerbatimToScantokensStuffAndCountersToStack#1{%
\endgroup
\NewDocumentCommand\InnerVerbatimToScantokensStuffAndCountersToStack{mmm+v}{%
\endgroup
\expandafter\@gobble\StuffAndCountersToStack{##1}{##2}{##3}{%
\begingroup\newlinechar=\endlinechar
\scantokens{\endgroup##4#1}%
}%
}%
}%
\catcode`\%=12\relax
\InnerVerbatimToScantokensStuffAndCountersToStack{%}%
%=== End of code of \VerbatimToScantokensStuffAndCountersToStack =========
\makeatother
\documentclass{article}
\usepackage{graphicx}
\usepackage{float}
% Load hyperref after float !
\usepackage{hyperref}
\NewStack{\laterfloats}
\renewcommand{\thefigure}{\thesection.\arabic{figure}}
\csname @ifundefined\endcsname{theHfigure}{}{%
\renewcommand{\theHfigure}{\theHsection.\arabic{figure}}%
}%
\csname @addtoreset\endcsname{figure}{section}
% \ref without hyperlink:
\csname @ifpackageloaded\endcsname{hyperref}{%
\newcommand\myref{\ref}%
}{%
\newcommand*\myref{\ref}%
}%
\begin{document}
\listoffigures
\section*{Introduction}
Please see figure~\ref{fig:one} and \ref{fig:two} and \ref{fig:three}
and \ref{fig:four} in Appendix~\ref{app:allimg}.
\section{First section}
Delayed figure~\ref{fig:one} and delayed figure~\ref{fig:two} are defined in this section.
\StuffAndCountersToStack{\laterfloats}{figure}{section,figure}{%
\begin{figure}[H]
\centering
\includegraphics[width=50pt]{example-image-a}%
\caption{First image}%
\label{fig:one}%
\end{figure}%
}%
\StuffAndCountersToStack{\laterfloats}{figure}{section,figure}{%
\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{example-image-b}%
\caption{Second image}%
\label{fig:two}%
\end{figure}%
}%
\section{Second section}
Delayed figure~\ref{fig:three} is defined in this section.
\VerbatimToScantokensStuffAndCountersToStack{\laterfloats}%
{figure}%
{section,figure}%
?%<-start of verbatim-argument
\begin{figure}[H]
\centering
\begin{tabular}{|c|}
\hline\
\begin{minipage}{.27\textwidth}
% Indenting of source code does matter with verbatimized arguments!
\begin{verbatim}
1 AB % & _^~# } {
2 AB % & _^~# } {
\end{verbatim}
\end{minipage}
\\\hline
\end{tabular}
\caption{figure with verbatim}%
\label{fig:three}%
\end{figure}%
? %<-end of verbatim-argument
\section{Third section}
Delayed figure~\ref{fig:four} is defined in this section.
\StuffAndCountersToStack{\laterfloats}{figure}{section,figure}{%
\begin{figure}[H]
\centering
\includegraphics[height=240pt]{example-image-c}%
\caption{Third image}%
\label{fig:four}%
\end{figure}%
}%
\appendix
\section{An appendix}\label{app:a}
\begin{figure}[H]
\centering
A figure in appendix \myref{app:a}
\caption{A figure in appendix \myref{app:a}}
\end{figure}
\subsection{A subsection of appendix \myref{app:a}}\label{app:allimg}
Here come all the delayed floats.
\FlushAndClearStack{\laterfloats}
\end{document}