Rather than try to change the actual aux and toc files, I just write an additional file, fauxtoc.toc, that mimics the toc file, but is unexpanded.
This version is implemented for \chapter and \section, since that was what was mentioned by OP. Additional sectioning can be added.
The method draws on egreg's answer to this question: Writing \\ to a File
\documentclass{book}
\usepackage{xpatch}
\makeatletter
\let\protected@iwrite\protected@write
\xpatchcmd{\protected@iwrite}{\write}{\immediate\write}{}{}
\let\svchapter\chapter
\let\svsection\section
\renewcommand\chapter{\@ifstar{\svchapter*}{\mychapnostar}}
\newcommand\mychapnostar[2][]{%
\ifx\relax#1\relax\svchapter{#2}\fauxtocwrite{chapter}{\thechapter}{#2}%
\else\svchapter[#1]{#2}\fauxtocwrite{chapter}{\thechapter}{#1}\fi%
}
\renewcommand\section{\@ifstar{\svsection*}{\mysectnostar}}
\newcommand\mysectnostar[2][]{%
\ifx\relax#1\relax\svsection{#2}\fauxtocwrite{section}{\thesection}{#2}%
\else\svsection[#1]{#2}\fauxtocwrite{section}{\thesection}{#1}\fi%
}
\newcommand\fauxtocwrite[3]{%
\edef\tmpA{\thepage}%
\protected@iwrite\tempfile{}{\detokenize{\contentsline{#1}}%
{\detokenize{\numberline}{#2}\detokenize{#3}}{\tmpA}}%
}
\makeatother
\newwrite\tempfile
\AtBeginDocument{\immediate\openout\tempfile=fauxtoc.toc}
\AtEndDocument{\immediate\closeout\tempfile}
\begin{document}
\tableofcontents
\chapter{Sample chapter $\hat{z}acffr$}
\chapter[$\hat{z}acffr$]{Next}
\section{This is a sample section $\tilde{d}$}
\end{document}
This produces a file fauxtoc.toc, which matches the proper toc file, except that the sectioning names are unexpanded
normal.toc:
\contentsline {chapter}{\numberline {1}Sample chapter $\mathaccent "705E\relax {z}acffr$}{3}
\contentsline {chapter}{\numberline {2}$\mathaccent "705E\relax {z}acffr$}{5}
\contentsline {section}{\numberline {2.1}This is a sample section $\mathaccent "707E\relax {d}$}{5}
fauxtoc.toc:
\contentsline {chapter}{\numberline {1}Sample chapter $\hat {z}acffr$}{3}
\contentsline {chapter}{\numberline {2}$\hat {z}acffr$}{5}
\contentsline {section}{\numberline {2.1}This is a sample section $\tilde {d}$}{5}
\begin{document}
\chapter{This is a sample chapter $\hat{z}acffr$}
\section{This is a sample section $\tilde{d}$}
\end{document}
– Saravanan.O Apr 23 '19 at 10:05\MakeRobust{\tilde}in the preamble. – egreg Apr 23 '19 at 13:04