Here are the possible scenarios
1) If you contract to bill by the hour, then it would be unethical to do otherwise. Whether or not you re-use code (assuming you are legally entitled to do so), is a non-factor.
2) If you provide a fixed quote, then if you are able to deliver high-value for less effort on your part, you have every right to do so.
Both approaches are valid (bill by the hour or fixed-price) and re-using your code (provided you are legally permitted to do so) is a 'given' in today's world.
In fact, I try to find a happy-medium by passing on some cost savings, and improving my $$$'s made per hour, by taking the following approach with clients:
"I've done a similar project before and can re-use a lot of the code, so I can save you some money on the development."
Personally, my preference, as a freelancer, is 'fixed-price, fixed-scope' projects and I stick to that - so if I've done $50,000 worth of development work for one client, and it's going to take me 10% of the time, I'm not going to charge only $5,000 - I'd charge $12,500, and here is my rationale:
1) The client is only paying 25% of the 'full development' cost - they are saving significantly;
2) Your clients are in business to make money - so are you and you are not a 'charity,' you deserve to earn for your work and for the 'value' you provide.
(ASIDE: Of course, I make special exceptions for not-for-profits and charitable organizations - and help them out when I can).
On the flip-side, if I get a paid project to develop code that I know I'm going to be able to re-use and resell, then I might quote much lower than the actual 'cost per hour' to develop - it's a smart business move, because you've now added to your library.
You can then go to clients and say, "I've just developed this for client XYZ and I thought can provide these 'upgrades' to your site for a reduced a cost if you'd like to incorporate these changes."
Your a Freelancer and Entrepreneur - this is the name of the game - as long as you are being honest and transparent with your clients, there is nothing unethical about these approaches - it is understood that this is the way things are done.
It is also understood that building relationships based on trust is critical to long-term business success!
(CAVEAT: Use common-sense here. If you use this approach with a client's direct competitor, in my view, you are being unethical (and sleazy)), but for example, if you build a 'Store Locator' feature for client that sells Men's Gifts, and you have small chain 'Pet Stores' - you can safely use this approach).
Remember that, especially when getting into developing 'custom applications,' pricing is very 'arbitrary.'
Charge too little, and your clients are likely to not respect your level of expertise.
Charge too much, and your clients will feel like you are taking advantage of them.
If you can, try and have a frank discussion with the client of what they feel the project is worth - ask them! (you'd be surprised how often they throw out a bigger number than you had in mind) - and seek some consensus.
There is some 'safety' in charging per hour - lots of people prefer that - but you are limiting your potential to earn money - and being able to re-use code and use code repositories, etc. should enable you to earn much more overall - while delivering better value.
So questions like, "What was the budget you had in mind for this project?" are powerful tools in your arsenal as a freelancer who has to cost out projects.
If they name a price you're happy with, then just respond with, "Yes, we can do that," dig into your code library, make money and make your client happy.