There is this nice animation of a 2-stroke engine with an expansion chamber
Source
It works like this:
While moving downwards after ignition, the piston exposes the exhaust opening, and the burned gas streams into the exhaust pipe like a (high pressure) shock wave.
Due to the inertia, this gas will create a slight vacuum wave behind it, which helps to suck out more burned gas, but also fresh gas as soon as the intake opening is uncovered.
The first cone helps to increase the vacuum: When the gas travels through the pipe with a certain speed, it travels through a certain volume per time. If the cross section is increased and the speed remains the same, the wave travels through a larger volume. This creates more ... uhm... vacuum volume behind the wave. It's a bit hard to explain.
OK, now we have fresh gas in the cylinder, but also in the manifold.
The shock wave now hits the right cone and gets reflected. I.e. you now have a shock wave running towards the cylinder. It hits the fresh gas right in the moment when the intake opening is covered by the piston, and presses this gas into the cylinder. When the piston covers the exhaust opening, too, the fresh gas already is under some pressure.
This way, the exhaust forms some kind of compressor, increasing the volumetric efficiency / power of the motor.
The shape of the exhaust is very critical with respect to timing: The length of the pipe between exhaust opening and first cone defines when the amplified vacuum wave reaches the cylinder - it should be there when the intake openings are exposed and fresh gas can be sucked out of them. And the distance to the second cone defines when the reflected shockwave reaches the cylinder. Again: This should happen when the intake is already covered, and the exhaust is not yet.
This means the exhaust pipe is designed for a specific RPM, where you get the maximum gain in power.
However, the angles of the cones allow to broaden the RPM range where the motor develops its power, at the cost of maximum power.
For example, here are power / torque curves for three exhaust systems on the same scooter:

First, it's notable that the motor starts to develop some power right above 5000RPM because there the exhaust starts to work.
- The blue curve is a quite narrow peak with a maximum at 7700 RPM. it looses power quite rapidly for higher/lower RPMs.
- The red curve is shifted to higher RPM, where it should develop more power - but instead, it's designed for a wider RPM range. So, the max. power is similar to that of the blue curve, but the RPM range is about twice as wide.
Finally, the design depends on the needs of the vehicle, too. A motor cross bike usually has a transmission with several fixed gears and so runs over a wide RPM range. In contrast, scooters usually have a variomatic, which allows the motor to run on a certain, constant RPM.