I was wondering if a locked iPhone (with a contract of 2 years) can be updated to iOs 7 and still working well and under the same contract.
There is no reason this should not work. Assuming your model supports iOS 7 of course.
I'd like to be able to tell you more. But there is just not much to say.
The lock to a certain provider is not affected by an upgrade to iOS 7. Provider settings will just be the same as well.
iOS Updates are controlled by Apple, not by your provider. So you're free to update your phone any time, as long as it's supported on your model.
I'd also ask my provider if they would be willing to remove that lock, most of them no longer insist on keeping your phone locked to their network anymore, and might be persuaded with a little begging.