I have always believed that \input was strictly equivalent to copy-pasting some code in a master latex file. But I currently experience this strange behaviour. Here is a minimal example.
My main file is:
\documentclass{article}
\begin{document}
\begin{tabular}{lcc}
\input{table_file}
\hline
\end{tabular}
\end{document}
and the inputted file is table_file.tex:
$T$ & 2.3 & 1.3 \\
average & 9.1 & 0.393 \\
Compiling the main tex file throws a string of errors. Here is the relevant piece of the log file:
(./table_file.tex)
! Misplaced \noalign.
\hline ->\noalign
{\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
l.5 \hline
! You can't use \hrule' here except with leaders. \hline ->\noalign {\ifnum 0=}\fi \hrule
@height \arrayrulewidth \futurelet...
l.5 \hline
! Missing number, treated as zero.
<to be read again>
\futurelet
l.5 \hline
! Illegal unit of measure (pt inserted).
<to be read again>
\futurelet
l.5 \hline
I'm not sure what is going on here... If I try to copy-paste the contents of table_file.tex into the main file:
\documentclass{article}
\begin{document}
\begin{tabular}{lcc}
$T$ & 2.3 & 1.3 \\
average & 9.1 & 0.393 \\
\hline
\end{tabular}
\end{document}
it now works flawlessly (no error in the log).
Last (important) thing: if I compile the main file without the \hline, there is no issue.
Any idea what is going on and how to remedy the issue? I'm relying heavily on inputting table rows into tabular environment so I'm eager to understand what is creating this!

\relax the content of the file \relaxif you try that you will get essentially the same error – David Carlisle Nov 19 '21 at 21:24\\before\hline. This would fix the error, but it would of course add an additional empty row. – Jasper Habicht Nov 19 '21 at 21:59