I assume you can’t export the Blender physics to your game, so you’ll have to be using some form of “translation” to make the flag animation work in your game. Many flag animations, especially the looping type, use a form of vertex keyframe animation, commonly called morph targets, or, in Blender, shape keys (or RVKs – relative vertex keys – for the really old-time Blender users.)
In the Export menu, you can export a selected object’s animation as an MDD file. Use File>Export>Vertex Keyframe Animation (.mdd). You can then import the MDD data as shape keys on a duplicate of your cloth mesh but with the cloth modifier disabled or removed. Use File>Import>Load MDD to mesh RVK.
With the Cloth animation set up as shape keys, you can then duplicate your starting shape key as a final key, and manually build a transition from the last frame of the cloth sim to the final key (which matches the first key) by creating a series of intermediate shape keys.
To keep things manageable, you can probably use the frame-step option in the Import process to limit the number of active keyframes you’ll have to deal with. Creating the intermediate “synthetic” keys will take some careful choices of the number of steps it’ll take, and probably some tweaking with the Sculpt tools, but I think you should be able to get a good loop this way. Getting the loop to a certain frame count will take pre-planning, and once your loop is finalized, you can decide which keys work best and edit them into the proper sequence length.