How to determine the thickness of an airfoil?
Factors for determining the wing thickness during the aeroplane design procedure:

Determine the required structure height, which follows from the aspect ratio determined by the aerodynamicists: the cantilever ratio, which is the structural wing semi-span divided by maximum root thickness. Statistical analysis has found that transport aircraft usually have a ratio between 18 and 22, lower means a lighter wing but more drag.
Stall behaviour: for thin wings the leading edge stall dominates, for thick wings trailing edge stall which is more gradual. This imposes a minimum thickness.
For aircraft cruising at M &gt; 0.5: the wing thickness must be such that dive Mach number remain subcritical. Imposes a maximum thickness.
For good max $C_L$ a value from the sweet spot between 12 and 15 should be selected, see below = fig 7-9 from Torenbeek.


Torenbeek then concludes:

It is concluded that the root section thickness of transport aircraft should be chosen such that a good cantilever ratio is obtained. For a given taper ratio this implies that the thickness ratio at the root will increase proportionally to the aspect ratio. A thickness ratio of between 15 and 20 percent is in the interest of good performance when using relatively simple trailing-edge high-lift devices and provides adequate room for retracting the undercarriaqe. Thickness ratios above 20 percent may show diminishing returns due to the increasing profile drag and the relatively low maximum lift and this, in turn, limits the aspect ratio to a maximum of approximately 13 for cantilever wings.
Tip sections (without flaps) should be between 10 and 15 percent in order to attain a high maximum lift. This reduction relative to the root is also in favor of low structural weight.