generally speaking if it's 5w30 or something it's ok in a pinch as a lubricant because it can form a thin film layer and flow into some small crevices, however motor oil is not formulated for finishes, wood/plastics, or wicking properties and isn't really ideal for for surface lubrication (going from a cold gun to one that warms up and keeping lubricants in place). firearms are composed of a variety of materials and often have both large flat surfaces, close fitting surfaces, and close fitting clearances. these work best with lubricants that do not attract moisture or debris, are able to stay in place with mild handling or motion or temperature variances, and can be applied thinly to avoid pumping.
3-in-1 oil, mineral oil, sewing machine oil, all can work for automatic handguns because they are thin enough to lubricate the moving parts and tend to stay in place. in some environments like repeat rain exposure, salt from sweat or the ocean spray, or in deserts, they can emulsify, flash/evaporate and not form a film, or separate and thin and run off. additionally carbon and various salts used in cheaper ammo can combine with some components of the oil and thicken it unexpectedly. 3-in-1 is an okay and safe lubricant largely due to the naphtha, petroleum-based ingredients, while gun oils (for example i'll pick Hoppe's lubricating oil), often have cyclohexane, and ethylbenzene which greatly reduce water beading or wicking in the area (forming a barrier against oxygen) and absorbing oxygen through chemical bonding. other compounds typically are used as a thickener or as a bonding agent to keep the solution in place and together.
the general rule of thumb is to avoid molybdenum lubricants and stick with lithium based or petroleum based ones, with lithium soap forming a detergent/dispersant grease compound that is excellent for large moving surfaces like bolt raceways, lugs, cam surfaces, and other massive moving parts. a light machine oil of some kind (and this can really be anything that has the correct properties) is used on small parts, parts that fit closely together that might have a pump out effect or require wicking into a crevice, or as a light surface protection from water or other corrosive substances when applied thinly regularly, does not attract fouling easily, and is safe to use on all surfaces and components (plastic/wood/steel/alloy) of a firearm. if you have a blued firearm, avoid ammonia based solvents or heavy ester compounds to preserve the bluing.
most springs are to be lightly oiled, gas pistons assemblies are to have very thinly applied greased, gas ports and small gas tubes are to be cleaned and kept dry (they are subject to hot pressured gases that carbon coat them and other than obstruction do not need lubrication). chambers should be free of debris and a brass brush used now and then on inspection, the bore should be flushed with either near-boiling hot water and alternating patches of light oil and dry patches used to achieve a bright bore, then a final pass with a well-oiled patch. it is preferable to go in the same direction as the bullet's travel and if going the other way it's a good idea to use a muzzle device to center the rod or take precautions to avoid damage to the crown. locking lugs, bolt raceways and other large moving parts should have a dab of lithium grease spread thinly and the part itself used to move the grease around. trigger mechanisms should use a light machine oil applied with a dropper near pivot points and at engagement surfaces with the exception of the sear which should have a small drop of grease evenly spread to transparency. parts that rotate like a revolver's cylinder axel should also get a thin layer of grease, same like a bolt raceway.
specifically for hunting rifles and shotguns, a lubricant that has a strong wax emulsifier applied immediately before a hunt can greatly protect a firearm when doing upland waterfowl hunting or stalking through brush and protect the oil layer under the wax layer. the wax layer (rem oil for example) is not a rust preventative itself, but is handy for getting water out of places it shouldn't be. WD-40 is a similar thing - it isn't a lubricant or rust preventative but is handy to remove water from an area or keep water out of that area.
for competitive shooters, a copper sulfide based grease is very nice for shotgun bolts and bolt carriers, lifters (small surface area, but large moving part), the interior of receivers, and for slide action rails.