How can I 'lock' the position of an object when applying curve displacement?
I recommend using the [Wave Modifier] for various reasons including


The Wave Modifier is often used for this purpose.  Its purpose is very clear.
Your curve above may not be long enough for longer repetitive motion and the endpoints tangents could affect the final result.
The difficulty you are already experiencing
The Wave Modifier has a [falloff] to keep the flag attached to the pole.  No Pun Intended. The selected empty serves this purpose in the image above.
As an alternative that you can create a vertex group to limit the vertex movement on the flag mesh near the pole, to zero.
As a [Not Recommended] alternative you could animate the curve rather than moving it.