They both would work if they are within the voltage range. However, they do not work the same. Of course, besides dimension differences, there are different parameters that change when having different voltages and also depending on the capacitor type.
For ceramic capacitors you have to consider the bias voltage (VDC). That is, when increasing the voltage the capacitance decreases. You can see the difference between two 100 µF capacitors, one rated at 25 V and the other to 6.3 V. Both would support 5 V, but the capacitance of the 6.3 V capacitor would be lowered (around 50%). The bias voltage is actually dependent on size rather than the capacitor voltage level, but it is true that higher voltage levels usually means higher volume.
Aluminium electrolytic capacitors are not as vulnerable to the bias voltage problem as ceramic ones. But capacitors with a lower voltage rating usually have higher ESR. That is something that might be considered (especially if there are no ceramic capacitors that have a very low ESR around). Also, tolerance values are usually worse for a higher voltage level.
So in general they would work the same for most applications. But there are some issues to consider when choosing the voltage level. The safest choice would most likely be to have just the voltage level needed for your application with some margin. But going with higher voltage levels, like in your case, is not usually a problem. It is more critical when going for lower voltage levels. Here you have a small recap of different capacitor types.
Graph: Murata Electronics.
Table: NIC Components.