The word sanctuary has several related meanings and connotations. A sanctuary is a place of rest and of safety, as well as being a holy place. The word lodge also suggests a place for a traveler to rest. The speaker compares the orchard with a sanctuary because it is a safe place for the butterfly. As always in Wordsworth's poetry, the speaker's love of nature has a religious quality, meaning that all natural environments are holy places, though they are not all equally safe and welcoming.
The figure of speech here is a simile. This is because the use of the word as shows that the speaker is comparing the orchard to a sanctuary rather than saying that it is one. If the word as were not present, it is debatable whether the image could be called a metaphor, since, in the sense of being a safe resting place, the orchard really is a sanctuary.
The use of a simile here, therefore, calls attention to the word sanctuary and highlights the other qualities of such a place that it does not share with the orchard. Appropriately enough, one modern use of the word sanctuary, which would not have been familiar to Wordsworth, is a place set aside for wildlife to flourish.