Why: Occasions may arise when you feel it is necessary to keep a butterfly indoors rather than release him or her to the great outdoors.
Such an occasion is a butterfly with sufficient wing damage that it cannot fly. This sort of damage can result from failure to "pump up" the wings due to delayed escape from the pupa or the just-emerged butterfly walking to a cramped location that doesn't allow the wings to pump up fully, or wing breakage before they have had a chance to harden; or one or more wings may have not formed properly in the pupa.
It also seems a bit inhumane to release into a very cold outdoors a butterfly that has accidentally emerged due to being kept in a too-warm room during the winter.
In any event, it is possible to successfully feed a swallowtail butterfly and keep it alive for weeks---6 weeks is our record, and it included a 2-week camping trip to Yosemite! Yup, the butterfly went with us. This particular butterfly (Madame Butterfly, as we called her) emerged from her pupa with very damaged wings, and while she made regular hearty attempts to fly each day of her 6-week life, she had to content herself with merely making buzzing noises.
Madame Butterfly is pictured below a couple of hours after hatching. As you can see, she is not going to be a flier, although she was otherwise healthy and robust.
Living quarters: Our flightless butterflies have generally lived in plastic containers (slick walls prevent climbing out) with paper towels and some leaves as floor covering and with open tops--they're not about to fly away, after all.
Food: We have been able to get our butterflies to feed by providing them with a special concoction that maybe only butterflies could love: a mix of sugar or honey water (about 1/2 tsp of either in 1/2 cup of water) with 1/2 tsp of soil from the garden and few drops of urine (human is OK), thus roughly simulating the contents of a typical grungey mud puddle containing animal urine. Butterflies seem to prefer these puddles to clean water, perhaps because there are lots of nutrient goodies in the grunge.
This mixture can be offered in a bottle cap or other small flat-ish container with a bit of paper towel or napkin in it. The liquid is adsorbed onto the paper, but if the paper is saturated, the liquid is available to a probing proboscis. A small piece of solution-saturated kitchen sponge works too. We have found that some butterflies require a little coaxing---like using a wooden toothpick to very gently uncoil the proboscis so its tip can be directed toward the mixture. Best to first let them try to find the mixture on their own, which they are more likely to do if they happen to walk on mixture-saturated paper towel.
You can also try making fake yellow flowers and put the food mixture into a short section of pinched-off drinking straw (or whatever else comes to mind) in the center of the flower. Or, if you have swallowtails feeding in your yard, grab some of those flowers and bring them in for your little one!
How soon to feed: A newly-emerged butterfly is content to not eat for at least a couple of days, if not a week, so there is no need to panic over failure to eat right away. Give the critter time and figure that the hungrier he/she gets, the more likely your provided food mixture will be looked for and found.
Age-related changes in nurtured mutants: Do not be alarmed if your carefully nurtured flightless butterflies happen to lose a leg or three during their lives in your plastic container. This is normal wear-and-tear and doesn't seem to bother the butterflies in the slightest, although it may affect their gait. They will also try to fly, thus beating (buzzing, actually) what wings they have for minutes on end, and perhaps whacking them against the sides of the plastic container or against objects in the container. This may result in pieces of wings being thrown off, gradually reducing the wings to a stubbier appearance. There is pathos here, but again, chalk it up to normal wear-and-tear and don't lose sleep over it. Madame Butterfly had managed to reduce her wings to small stubs and had a leg-count of perhaps 3 by the time she was called to the Great Butterfly Beyond. But she never lost her butterfly optimism and spirit.