Begin any hat pattern with a provisional cast on and knit the hat to the top. Finish off the top. Green yarn is a provisional cast on.
After the outer hat is done, I remove the green yarn and put the live gray stitches on a needle. Then I attach gray yarn and knit the lining in the other direction.
After the lining is knit just like the hat, it fits inside, making a hat with two layers and the yarn ends neatly hidden between layers.