First of all, it does not prevent the virus. It is a vaccine against four specific strains of the virus. There are more than 100, and they are present in over 90% of sexually active people. Also, no it doesn't. The virus itself does not cause cancer. A persistent infection with the same strain of the virus can lead to "precancerous" conditions, meaning it makes it more likely that cancer will occur, not "causing" it.
And if it prevents those 4 strains from occurring in exposed individuals, it prevents those 4 strains of the virus. That is what a vaccination does, and why it is called "preventive medicine."
And without the precancerous condition, cancer would not occur. Etiology can and is traced directly back to infection with the HPV.
Here is the closest way I can think of to explain this. Suppose someone said, "Hey, sunlight causes cancer. So I know how I will cure that, I'll never go in the sun again." Is that a smart idea? Sure, exposure to UV rays can cause damage to the DNA in your skin and lead to skin cancer. It doesn't "cause" cancer, but it can be a catalyst for the conditions that give rise to cancer. But there is also scientific data showing that lack of sunlight would lead to Vitamin D deficiency. Vitamin D is known to interact with the immune system and fight tumors. There is also data showing that people who spend more time indoors are actually more likely to get skin cancer, since skin that is infrequently exposed to UV rays is more likely to be harmed by them. Then there is the fact that this is just one way that skin cancer can be caused, there are tons of other which have nothing to do with the sun at all.
For any disease to occur, one must have a predispositon and a triggering factor. Unfortunately, predisposition is difficult to determine unless symptom of disease indicating that predisposition is present. Are you really suggesting that limiting sun exposure does not prevent skin cancers? If you are, you truly need to go back and check some reliable medical websites. Please provide a link that shows a positive correlation between time spent indoors and the presence of skin cancer.
This is extremely similar to what is happening here. You are confusing cause and effect. Saying that many women with cervical cancer have been found to have HPV and therefore HPV "causes" cancer is totally misleading. That's like saying, "Well, a lot of women with cervical cancer also have breasts, and this high correlation rate leads us to believe that breasts cause cervical cancer, so we're recommending mastectomies to reduce that risk". The majority of women have HPV, just like the majority of women have breasts. Certain strains of HPV, in specific situations, and when combined with other factors, can cause physiological responses which can increase the likelihood of cancer forming. HPV does not "become" cancer, and it does not "cause" cancer in the way that you seem to think it does.