Since the outbreak of the COVID-19 pandemic, Fangcang shelter hospitals have been built and operated in several cities, and have played a huge role in epidemic prevention and control. How to use medical resources effectively in order to maximize epidemic prevention and control is a big challenge that the government should address. In this paper, a two-stage infectious disease model was developed to analyze the role of Fangcang shelter hospitals in epidemic prevention and control, and examine the impact of medical resources allocation on epidemic prevention and control. Our model suggested that the Fangcang shelter hospital could effectively control the rapid spread of the epidemic, and for a very large city with a population of about 10 million and a relative shortage of medical resources, the model predicted that the final number of confirmed cases could be only 3.4% of the total population in the best case scenario. The paper further discusses the optimal solutions regarding medical resource allocation when medical resources are either limited or abundant. The results show that the optimal allocation ratio of resources between designated hospitals and Fangcang shelter hospitals varies with the amount of additional resources. When resources are relatively sufficient, the upper limit of the proportion of makeshift hospitals is about 91%, while the lower limit decreases with the increase in resources. Meanwhile, there is a negative correlation between the intensity of medical work and the proportion of distribution. Our work deepens our understanding of the role of Fangcang shelter hospitals in the pandemic and provides a reference for feasible strategies by which to contain the pandemic.