My concern would be that the denim is very strong whereas flannel is relatively weak. I think I would iron on a nylon tricot interfacing to "beef up" the flannel squares. You can use parchment paper as a non-stick surface underneath and above (so the nylon tricot interfacing doesn't melt onto your iron or ironing board). You can probably find some nylon tricot interfacing at JoAnn's. Pellon's Easy-Knit is one brand. Here is another on Amazon:
https://www.amazon.com/FusiKnit-Tric...dp/B005Q1OCZW/
I like the fusible nylon tricot interfacing, but there are probably other types of interfacing that would also do the job. I think you would not have to worry about the flannel shrinking if you use an iron-on interfacing, and it would make the flannel a closer weight to the denim so you would not have to worry so much about the flannel fraying at the seams. It is always a good idea to use a 1/2" seam allowance for flannel, but again I think you could get away with 1/4" if you use an iron-on interfacing first.
Are you planning to tie the finished piece? Or machine quilt it? Machine quilting is another safeguard against shrinkage and seam fraying. It stabilizes the quilt so there is less stress put on the seams.
Edit: Pre-washing flannel is a good idea when you have yardage, but becomes more problematic when you have 5" squares. Some flannels do not shrink at all; others shrink a *lot*. If you soak the squares, you could end up with different sizes. If you want to use them as 5" squares, it's probably safer to use an iron-on interfacing. I'm pretty sure nylon tricot won't shrink; I don't know about others.