There are two things that cause this:
Paragraph indentation. The standard paragraph indentation is added before the tikzpicture, you can disable that for a single line with \noindent, i.e. \noindent\tikz...
When you draw a line, the bounding box will actually extend by half the line width beyond the end coordinates, as you can see from this example:
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [line width=5mm] (0,0) -- (1,0);
\draw [very thin, red] (0,-0.5) -- (0,0.5);
\draw [thin, blue] (current bounding box.south east) rectangle (current bounding box.north west);
\end{tikzpicture}
\end{document}

The blue line indicates the bounding box.
If you add line cap=rect, the line will extend to fill that blank space, and you pgf has the handy macro \pgflinewidth that has the width of the current path. Hence, you can do \draw[thick,line cap=rect] (0,0) -- (\linewidth-\pgflinewidth,0) ....
Working example, as egreg mentioned you shouldn't use minimal (Why should the minimal class be avoided?):
\documentclass{article}
\usepackage{tikz}
\newcommand{\TotalMarks}[1]{%
\tikz\draw[thick,line cap=rect]
(0,0) -- (\linewidth-\pgflinewidth,0) --
++(0,2em) -- ++(-2em,0) --
++(0,-2em) node[pos=0.6,left]
{\makebox[2.9cm]{\textbf{Total: #1 marks}\hfill}};}
\begin{document}
\noindent\TotalMarks{2}
\end{document}
linewidthtry this:\tikz\draw[thick](0,0) -- (\linewidth-21pt,0)– AndréC Sep 12 '20 at 20:50\noindent\tikz ..– Torbjørn T. Sep 12 '20 at 20:54minimal. It's not for typesetting any type of document. – egreg Sep 12 '20 at 20:56showframepackage – AndréC Sep 12 '20 at 20:57parindentis set to be equal 0pt. I have edited the question accordingly. – Logos Sep 12 '20 at 21:00