There are a few fundamental difficulties.
The energy stored in a flywheel is a combination of its moment of inertia and its speed. To get a higher moment of inertia you either need more mass or a larger diameter. The problem being that bicycles tend to be very sensitive to both weight and space. This leaves you with speed, firstly this will require quite a high gear ratio to get from the relatively low speeds of a bicycle wheel to the high speeds required for an effective flywheel as well as a mechanism to engage and disengage it smoothly and transfer between extracting and imputing energy, this adds weight and complexity.
Also a flywheel with a useful amount of energy will have a string gyroscopic effect which is a particular issue on a bicycle unless you have an even more complex system to mitigate it.
Equally high speed flywheels pose materials challenges for bearings and the flywheel itself which is trying to explosively pull itself apart and obviously even a light, low speed flywheel is going to need to be fully enclosed for safety.
The short answer is that with current technology an electrical system with batteries is always going to be more attractive, the technology is mature and well developed and for anything like reasonable cost is going to provide much better energy density and is much easier to package on a bicycle as well as allowing for a much greater degree of control. For example a digitally controlled electrical system can have many different modes of operation without any additional mechanical parts.