We use scrum technique to plan for short development lifecycle. It is very common that sometimes tasks gets moved or reallocated or deferred from the current sprint for multiple reasons. In that case there is a chance of resources getting freed up from the planned work. It may get difficult to allocate new tasks to them during sprint as mostly all projects are tied up at that point with planned work. What is the best way to plan resources in these situations?
Just give your resources some freedom. If it is agile - they will be happy.
"It may get difficult to allocate new tasks to them during sprint as mostly all projects are tied up at that point with planned work"
Project management smell.
If you have "pre-planned" all the work, that's not very Agile, is it? Agile == Flexible. You should be able to rearrange without breaking anything.
If your plan "breaks" you have too much plan and too little Agile.
You shouldn't over-plan this kind of thing.
One of the (wonderful) purposes of agile techniques is to try and remove a lot of unnecessary planning, as you admit that your project plans will change, and that if you hold to a tried and true planning method such as the common waterfall method (reqs->specs->design->dev->qa->release, etc) that you're going to go through a lot of needless iterations and wasted time.
Either plan less, or have a pool of activities that developers can pull from if they have flexible time to use (minor feature requests, old UI bugs, less important things that can be dropped if needed)
In that case there is a chance of resources getting freed up from the planned work.
First, I'd start to talk about people or team members, not resources ("respect people").
It may get difficult to allocate new tasks to them during sprint
You shouldn't allocate tasks to people (this sounds like micro-management). Tasks are in the queue (the sprint) and the team should self-organize to get items DONE, focusing on most important items first.
What is the best way to plan resources in these situations?
The best way is to not do it.