In this painting, Leonhard Euler is wearing what looks like a hastily-folded dishtowel on his head. What actually is it? Was it actually stylish in the mid-1700s or something weird or special?
Caps and turban-like pieces were often worn by working men as well as gentlemen in casual attire (Euler is wearing a banyan, so we'll assume the more worldly, casual attire). They could be both a substitute for the more formal (and less comfortable) wig, as well as keep the head warm and clean from dust/debris/smoke. What Euler specifically is wearing looks to be a more extreme version of this style of cap. It's literally a tube knotted or tied on top. His just has a great deal of extra after the tied off point. You'll see a great variety of styles, some knitted, some actually tied in a knot, some worn rather jaunty, and others oversized enough to begin to resemble crude turbans. Wrapping a kerchief about the head in a turban-like manner was also popular.