It depends.
The stresses on your body are different when you run on a hard surface (pavement) versus semi-soft (grass) versus very soft and shifting (sand).
Generally speaking, your joints take more impact on hard surfaces. But your muscles have to work harder to run on soft surfaces, and there is greater risk of muscle and tendon strains due to uneven terrain increasing the risk of stumbles, not to mention the ground literally shifting beneath your feet on something like sand (or gravel).
Running barefoot versus shod has different risk factors too. When barefoot, there is the obvious risk of stepping on something sharp, leading to cuts and puncture wounds. Thick-soled running shoes minimize this risk and also help to mediate the energy transfer between your body and the running surface. But they can also affect your gait. (Some studies found shod runners are more likely to heel strike, whereas barefoot runners are more likely to forefoot or midfoot strike.)
Bottom line: hard surfaces and a good pair of modern running shoes will improve your performance in terms of both speed and endurance. But if you're going to race on uneven and/or softer surfaces, you should train on them too so your body gets the chance to adapt to the different challenges of such surfaces. The literature on injury risk has largely found that while one individual may prefer and do better with one option than another, there is no general consensus on which is best for everyone.
There is, however, a greater risk of injury when you change up what you are doing. It doesn't matter which direction you are changing in (i.e.: transitioning from barefoot to shod, or vice versa). The stressors on your body are changing, and therefore the injury risk increases if the change is not introduced gradually and mindfully.
Say, for example, you habitually run in built-up running shoes on asphalt. You can go out any day and run 10K in your shoes on a road and be fine. Because your body has adapted to be able to handle that stress load. However, it would be inadvisable to suddenly ditch your shoes and/or switch to running on a beach and still attempt to do that same 10K at speed. Instead, you'd want to de-load, and build up your ability to run in the new style gradually (as you would if you switched to a different exercise).