It depends on the type of hat.
These are some hats that I’ve designed. All were knit from the bottom up and in the round, usually on double-pointed needles as that is my preference, but they could equally be knit on a circular needles.
The first row, and the last two on the right in the second row, involve reducing the number of stitches towards the end. The number of stitches at the end varies: Fluxions reduces to 6 stitches; Maquereau varies between 16 and 24 stitches according to head-size. For ‘reduction’ hats like these, the usual method* of finishing is to cut the yarn leaving a tail 6–10 cm long, thread the tail through the remaining stitches, cinch tight, and secure inside. The threading can be done with sewing (tapestry) needle, or you can use the knitting needles to ‘knit’ each of the stitches off, flicking the yarn tail through each.
Tiny Teddy and Shadow Pets have no reduction. The top of such hats could be sewn together using mattress stitch after binding off. However, the samples I worked for Tiny Teddy and Shadow Pets were closed using a 3-Needle Bind-Off** and an I-cord Bind-Off respectively. The instructions, iirc, were respectively Kitchener Stitch***, and mattress stitch with a separate i-cord sewn on afterwards.
These are two basic hat types. There are others – the ‘reducing’ hats can be worked top down, by increasing the number of stitches: this completely avoids having to sew/finish the hat. Some hat designers, like Woolly Wormhead, use very unusual construction methods which you just have to follow blindly, as it were: they WILL work, promise! Most patterns will give you reasonably detailed instructions for finishing, especially if it’s an unusual method.
If you’ve knitted a flat piece of knitting and want to turn it into a hat… the simplest way is to use mattress stitch. Sorry. You could crochet it together, too.
You’ll notice I give a lot of YouTube videos as examples. YouTube is a fantastic resource for knitters: you can generally find just about any knitting stitch, style, tip or technique there.
* – The pi hat (last on the right, bottom row) is completed by continuing the remaining stitches as an i-cord, to which the tassel is tied.
** – Ideal for ensuring your Pussy Hat’s ears stay perky.
*** – I personally recommend the knitted Kitchener stitch, as I only have Magic Disappearing tapestry needles. Also I hate sewing.