long yarn between needle

Hello everyone. I’m new to knitting. I’m trying to make a headband but i have a problem here. Whenever i try to knit my stitches, the yarn between my needle got longer and longer

I tried to redo it several times but the result is always same. So i tried making a small square to see the final result and the last stitch of the square is loose

I dont know why this happened. I tried looking for a video on how to fix it but i couldn’t find any. Does anyone know why this happened? Since i am a beginner, is this because of my tension? Thank you

Welcome to KnittingHelp!
It may partly be the cast on that you are using. At the top of the page is a Free Videos tab. Open it and look at knit or cable cast on or long tail cast on. You may be using thumb loop cast on which isn’t very sturdy and can gives a long strand betwwen sts.
There are also some neater ways to end the cast off that might help. I can’t access now but if you Google Knit Freedom, neater cast off end stitch you may find her helpful video.
You tension on the small swatch looks quite nice. Keep going. You’re doing well.

Thank you! I’ll try it