When Do Prompting and Prefix-Tuning Work? A Theory of Capabilities and Limitations