There is a missunderstanding here: You can not have two commands \documentclass{} in one TeX document.
Please see the following MWE I created from your given codes (package filecontents is only used to have three tex code in one MWE; this is only for testing purpose here, you can use your original codes of course):
\RequirePackage{filecontents}
\begin{filecontents}{\jobname-chapter1.tex}
\chapter{Chapter One}
Text for chapter one ...
\end{filecontents}
\begin{filecontents}{\jobname-chapterThomae.tex}
\documentclass{article}
\usepackage{tikz}
\makeatletter
\pgfmathdeclarefunction*{gcd}{2}{%
\begingroup
\pgfmathcontinuelooptrue
\pgfmath@xa=#1pt\relax % <-
\pgfmath@xb=#2pt\relax % <-
\ifdim\pgfmath@xa=0pt\relax
\pgfmathcontinueloopfalse
\pgfmath@xa=\pgfmath@xb
\fi
\ifdim\pgfmath@xb=0pt\relax
\pgfmathcontinueloopfalse
\pgfmath@xb=\pgfmath@xa
\fi
\ifdim\pgfmath@xa<0pt\relax
\pgfmath@xa=-\pgfmath@xa
\fi
\ifdim\pgfmath@xb<0pt\relax
\pgfmath@xb=-\pgfmath@xb
\fi
\loop
\ifpgfmathcontinueloop
\ifdim\pgfmath@xa=\pgfmath@xb
\pgfmathcontinueloopfalse
\else
\ifdim\pgfmath@xa>\pgfmath@xb
\advance\pgfmath@xa by-\pgfmath@xb\relax
\else
\advance\pgfmath@xb by-\pgfmath@xa\relax
\fi
\fi
\repeat
\pgfmathparse{int(\pgfmath@xa)}%
\pgfmath@smuggleone\pgfmathresult
\endgroup}
\makeatother
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=8]
\draw [-stealth] (-0.1,0) -- (1.1,0);
\draw [-stealth] (0,-0.1) -- (0,0.6);
\foreach \X in {1,...,7}
{\ifnum\X=1
\else
\draw (0.02,1/\X) -- (-0.02,1/\X) node[left,xshift={(-(1+pow(-1,\X)))*3pt}]{$\frac{1}{\X}$};
\fi
}
\foreach \X [evaluate=\X as \Ymax using {int(\X-1)}]in {95,94,...,2}%Το μέγεθος του πρώτου όρου καθορίζει το πλήθος των κουκκίδων, άρα και την απόσταση του «τριγώνου» από τον χ'χ.
{\foreach \Y in {1,...,\Ymax}
{\ifnum\X<6
\draw (\Y/\X,0.02) -- (\Y/\X,-0.02) node[below,fill=white]{$\frac{\Y}{\X}$};
\else
\draw[ultra thin] (\Y/\X,0.01) -- (\Y/\X,-0.01);
\fi
\pgfmathtruncatemacro{\TST}{gcd(\X,\Y)}
\ifnum\TST=1
\fill ({\Y/\X},1/\X) circle(0.05pt); %μέγεθος κουκκίδων
\fi
}
}
\foreach \X in {0,1,...,80}
{\fill (\X/80,0) circle(0.05pt); } %μέγεθος κουκκίδων
\end{tikzpicture}
\end{center}
\end{document}
\end{filecontents}
\documentclass{book}
%\includeonly{\jobname-chapter1} % or chapter2 or chapter3 or chapterThomae etc
\begin{document}
\include{\jobname-chapter1}
\include{\jobname-chapterThomae}
\end{document}
Copy this code to mwe.tex in a new directory of your computer and compile it with pdflatex mwe.tex. Then you will see the following error messages (and others more):
(mwe-chapter1.tex
Chapter 1.
) [1
{C:/Users/User/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}]
\openout2 = `mwe-chapterThomae.aux'.
(mwe-chapterThomae.tex
! LaTeX Error: Can be used only in preamble.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.5 \documentclass
{article}
Your command was ignored.
Type I <command> <return> to replace it with another command,
or <return> to continue without it.
The error message ! LaTeX Error: Can be used only in preamble. tells you that you can not call \documentclass{article in your tex code for the document as you did with \include{\jobname-chapterThomae}, because this file contains that second call of command \documentclass ...
Now let us rework the given MWE above and delete \documentclass, \begin{document) and \end{document) in your file \jobname-chapterThomae.tex and move the call for tikz and the correcting code into the correct preamble of your code. Please see that file \jobname-chapterThomae.tex starts now with \begin{center}:
\RequirePackage{filecontents}
\begin{filecontents}{\jobname-chapter1.tex}
\chapter{Chapter One}
Text for chapter one ...
\end{filecontents}
\begin{filecontents}{\jobname-chapterThomae.tex}
\begin{center}
\begin{tikzpicture}[scale=8]
\draw [-stealth] (-0.1,0) -- (1.1,0);
\draw [-stealth] (0,-0.1) -- (0,0.6);
\foreach \X in {1,...,7}
{\ifnum\X=1
\else
\draw (0.02,1/\X) -- (-0.02,1/\X) node[left,xshift={(-(1+pow(-1,\X)))*3pt}]{$\frac{1}{\X}$};
\fi
}
\foreach \X [evaluate=\X as \Ymax using {int(\X-1)}]in {95,94,...,2}%Το μέγεθος του πρώτου όρου καθορίζει το πλήθος των κουκκίδων, άρα και την απόσταση του «τριγώνου» από τον χ'χ.
{\foreach \Y in {1,...,\Ymax}
{\ifnum\X<6
\draw (\Y/\X,0.02) -- (\Y/\X,-0.02) node[below,fill=white]{$\frac{\Y}{\X}$};
\else
\draw[ultra thin] (\Y/\X,0.01) -- (\Y/\X,-0.01);
\fi
\pgfmathtruncatemacro{\TST}{gcd(\X,\Y)}
\ifnum\TST=1
\fill ({\Y/\X},1/\X) circle(0.05pt); %??????? ?????????
\fi
}
}
\foreach \X in {0,1,...,80}
{\fill (\X/80,0) circle(0.05pt); } %??????? ?????????
\end{tikzpicture}
\end{center}
\end{filecontents}
\documentclass{book}
\usepackage{tikz} % <===================================================
\makeatletter% <========================================================
\pgfmathdeclarefunction*{gcd}{2}{%
\begingroup
\pgfmathcontinuelooptrue
\pgfmath@xa=#1pt\relax % <-
\pgfmath@xb=#2pt\relax % <-
\ifdim\pgfmath@xa=0pt\relax
\pgfmathcontinueloopfalse
\pgfmath@xa=\pgfmath@xb
\fi
\ifdim\pgfmath@xb=0pt\relax
\pgfmathcontinueloopfalse
\pgfmath@xb=\pgfmath@xa
\fi
\ifdim\pgfmath@xa<0pt\relax
\pgfmath@xa=-\pgfmath@xa
\fi
\ifdim\pgfmath@xb<0pt\relax
\pgfmath@xb=-\pgfmath@xb
\fi
\loop
\ifpgfmathcontinueloop
\ifdim\pgfmath@xa=\pgfmath@xb
\pgfmathcontinueloopfalse
\else
\ifdim\pgfmath@xa>\pgfmath@xb
\advance\pgfmath@xa by-\pgfmath@xb\relax
\else
\advance\pgfmath@xb by-\pgfmath@xa\relax
\fi
\fi
\repeat
\pgfmathparse{int(\pgfmath@xa)}%
\pgfmath@smuggleone\pgfmathresult
\endgroup}
\makeatother % <========================================================
%\includeonly{\jobname-chapter1} % or chapter2 or chapter3 or chapterThomae etc
\begin{document}
\include{\jobname-chapter1}
\include{\jobname-chapterThomae}
\end{document}
Now it compiles without errors and two warnings (okay, resulting from filecontents!) to the following result:

\headheightand a warning that you are typesetting some text in cmr that does not have the characters but no errors – David Carlisle Jul 18 '19 at 19:37\includeonly{}command (see the edited post). – Kώστας Κούδας Jul 18 '19 at 19:52hapterThomae.texin your question. In your linked version there is for example an\end{document}included, that would cause an error ... – Mensch Jul 18 '19 at 19:59chapterThomae. But, as I said, alone thechapterThomaehas no problems. I can compile it alone without problems. Also, if I delete only the code of the Thomae's function (not all the chapter) I have no problems. I have problems only if I include all chapters and the Thomae's function code. – Kώστας Κούδας Jul 18 '19 at 20:42