According to my sources, electric bikes do not necessarily charge when you pedal. However, some e-bikes come with a feature called regenerative braking system that allows the battery to charge when you ride the bike, but this is not the case for all e-bikes. The battery of an electric bike usually recharges the same way as other small portable electrical devices by popping it off the frame and into the wall socket via a cable. So, the answer is that it depends on the specific e-bike model and whether it has a regenerative braking system or not (source: [Cyclingnews.com](https://www.cyclingnews.com/features/do-electric-bikes-charge-when-you-pedal/), [eBikeBuster](https://ebikebuster.com/do-electric-bikes-charge-when-you-pedal/), [Discerning Cyclist](https://discerningcyclist.com/do-electric-bikes-charge-while-pedalling/)).
There are electric bikes that are made to recharge as riders pedal, but most electric bikes don’t really have that feature. Even electric bikes that have the feature to recharge when riders pedal aren’t really much utilized that way as it still needs to be recharged on a wall mount as the pedaling won’t really do much on recharging the battery.
Riders could get the most recharging on the battery of the electric bike only when they could pedal hard or when riding downhill, that won’t be enough to fully replenish the battery but it would allow the electric bike to go for a bit further.
Practically, an electric bike with the feature that would recharge the battery with pedaling is not really a good choice. They are extra expensive than those without that feature but the gains are minimal.